//函数式编程概念:柯里化(currying):将多参数的函数转为单参数的形式
function currying(fn,n){
return function(m){
return fn.call(this,m,n);
}
}
function tailFactorial(n,total){
if(n == 1) return total;
return tailFactorial(n-1,n * total);
}
const factorial = currying(tailFactorial,1)
console.log(factorial(5));//120
函数式编程概念:柯里化(currying)
最新推荐文章于 2024-01-24 13:43:34 发布