zoukankan      html  css  js  c++  java
  • 猿辅导前端面经

    一面:

    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);
  • 相关阅读:
    Linux同一机器设置多个IP2019-7-6
    使用Apache服务部署静态网站2019-7-5
    系统状态检测命令2019-7-5
    简单的shell脚本
    常用的系统工作命令2019-7-4
    Lnmp架构部署动态网站环境.2019-7-3-1.4
    Lnmp架构部署动态网站环境.2019-7-3-1.3
    Linux安装ftp服务-详细步骤
    循环删除List集合的元素
    反射-父类获取子类属性并赋值
  • 原文地址:https://www.cnblogs.com/smalldy/p/13215107.html
Copyright © 2011-2022 走看看