js柯里化
function sum(a, b, c) {
return a + b + c
}
function curry(f) {
return function fn(...args) {
if (args.length >= f.length) {
return f.apply(this, args)
} else {
return function (...args2) {
return fn.apply(this, args.concat(args2))
}
}
}
}
const sc = curry(sum)
console.log(sc(1, 2, 3))
console.log(sc(1)(2, 3))
console.log(sc(1, 2)(3))