You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functioncurry(func){letlen=func.length,args=[];functioncombine(...arg){args=args.concat(arg);returncombine;}combine.sumOf=function(){if(args.length>=len){letres=func(...args);args=[];returnres;}else{thrownewError(`args is ${JSON.stringify(args)}`);}}returncombine;}letsum=(a,b,c)=>a+b+c;letcsum=curry(sum);console.log(csum(1,2)(3).sumOf());console.log(csum(1,2,3).sumOf());console.log(csum(1,5)(2).sumOf());
题目
普通 curry:
手写一个函数的柯里化,实现下面功能:
惰性 curry 之所以叫惰性,因为调用 sumOf 才显示地求值:
手写一个函数的柯里化,实现下面功能:
题解
普通 curry
惰性 curry
出处
作者:我是你找不到的小铭
链接:https://www.nowcoder.com/discuss/452433
来源:牛客网
The text was updated successfully, but these errors were encountered: