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 profunction 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}