68 字
1 分钟
手写curry

要求实现如下

const add = (a, b, c) => a + b + c;
const a1 = currying(add, 1);
const a2 = a1(2);
console.log(a2(3)) // 6
// curry pro
function curryPro(fn, ...outerProps) {
function curried(...middleProps) {
const concatArr = [...middleProps];
if (concatArr.length >= fn.length) {
return fn.call(this, ...concatArr)
}
return function (...innerProps) {
return curried.call(this, ...concatArr.concat(innerProps))
}
}
if(outerProps.length){
return curried(...outerProps);
}
return curried
}
手写curry
https://nollieleo.github.io/posts/手写curry/
作者
翁先森
发布于
2021-12-13
许可协议
CC BY-NC-SA 4.0