美文网首页
一个珂理化的面试题

一个珂理化的面试题

作者: TerdShow | 来源:发表于2019-07-24 13:38 被阅读0次
    // 实现一个add方法,使计算结果能够满足如下预期:
    // add(1)(2)(3) = 6;
    // add(1, 2, 3)(4) = 10;
    // add(1)(2)(3)(4)(5) = 15;
    
    function add(){
      let _args = Array.prototype.slice.call(arguments);
    
      let _adder = function(){
        _args.push(...arguments);
        return _adder; //返回adder 并用来收集后续参数
      }
    
      _adder.toString = function() {
        _args.reduce((a,b) => {
          return a + b;
        })
      }
    
      return _adder;
    }
    
    

    相关文章

      网友评论

          本文标题:一个珂理化的面试题

          本文链接:https://www.haomeiwen.com/subject/dukxrctx.html