首页 > 其他 > 详细

猿辅导前端面经

时间:2020-06-30 20:00:26      阅读:55      评论:0      收藏:0      [点我收藏+]

一面:

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);

猿辅导前端面经

原文:https://www.cnblogs.com/smalldy/p/13215107.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!