function curry(fn){
    // 代码
}

function add(a,b,c){
    return a + b + c;
}

const execAdd = curry(add);

execAdd(1)(2)(3) === 6; // true
execAdd(1,2)(2) === 6; // true
execAdd(1,2,3) === 6; // true

function mulit(a,b,c,d){
    return a * b * c * d;
}
const execMulit = curry(mulit);

execMulit(1)(2)(3)(4) === 24; // true
execMulit(1, 2)(3)(4) === 24; // true
execMulit(1, 2, 3)(4) === 24; // true
execMulit(1, 2, 3, 4) === 24; // true

这是2018年七牛云前端校招春招的一道题目

function curry(fn){
    let fnLent = fn.length,
        args = [];
    return function _curry(){
        for (const arg of arguments) {
            args.push(arg)
        }
        return args.length === fnLent ? fn.apply(this,args) : _curry;
    }
}

主要解题思路是fn.length

相关文章:

  • 2022-01-16
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2021-05-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
相关资源
相似解决方案