Overview
Implement curry(fn) — returns a curried version that accumulates arguments until fn.length is reached.
Examples
function add(a, b, c) { return a + b + c; }
const curried = curry(add);
curried(1)(2)(3); // 6
curried(1, 2)(3); // 6
curried(1)(2, 3); // 6Solution
Reveal solution
function curry(fn) {
return function curried(...args) {
if (args.length >= fn.length) return fn(...args);
return (...more) => curried(...args, ...more);
};
}curry.js
Curry
mediumcodingJavaScriptFunctions
Overview
Implement curry(fn) — returns a curried version that accumulates arguments until fn.length is reached.
Examples
function add(a, b, c) { return a + b + c; }
const curried = curry(add);
curried(1)(2)(3); // 6
curried(1, 2)(3); // 6
curried(1)(2, 3); // 6Solution
Reveal solution
function curry(fn) {
return function curried(...args) {
if (args.length >= fn.length) return fn(...args);
return (...more) => curried(...args, ...more);
};
}NameTopicDifficulty
103 of 103 problems