猿辅导前端面经
一面:
1、给定一组左闭右开的区间,如:
[1, 2), [3, 4), [4, 7), [6, 20)
输出将连续区间合并后的结果,如:
[1, 2), [3, 20)
let merge = function(intervals) {
    intervals.sort((a,b) => a.start-b.start)
    
    for(let i=0;i<intervals.length-1;i++){
        let interi1=intervals[i],interi2=intervals[i+1]
        
        if(interi1.end >= interi2.start){
            if(interi1.end < interi2.end){
                interi1.end=interi2.end
            }
            intervals.splice(i+1,1)
            i--
        }
    }
    return intervals
};
2、有一个长度为 N + 1 的整数数组,其中的元素取值范围为 1…N(包含1和N),并且元素取值覆盖 1…N(包含1和N)编程找到重复的数字
3、JS 的继承
//组合继承
function Parent(value){
    this.val =value;
}
Parent.prototype.getValue = function(){
    console.log(this.val);
}
function Child(){
    Parent.call(this, value);
}
Child.prototype = new Parent();
const child = new Child(1);
//寄生组合继承
Child.prototype = Object.create(Parent.prototype, {
    constructor: {
        value: Child,
        enumerable: false,
        writable: true,
        configurable: true
    }
})
//ES6继承
class Parent {
    constructor(value){
        this.val = value;
    }
    getValue(){
        console.log(this.val);
    }
}
class Child extends Parent {
    constructor(value){
        super(value)
        this.val = value;
    }
}
let child = new Child(1);
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号