function curry(fn) {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args);
}
return function (...more) {
return curried.apply(this, args.concat(more));
};
};
}
// Usage
const add = curry((a, b, c) => a + b + c);
const add5 = add(5);
const add5and3 = add5(3);
console.log(add5and3(2)); // 10
Create a free account and build your private vault. Share publicly whenever you want.