07

Curry of fixed arity

20 min·senior·

Implement curry(fn) such that:

const add = (a, b, c) => a + b + c;
const c = curry(add);
c(1)(2)(3);    // 6
c(1, 2)(3);    // 6
c(1)(2, 3);    // 6
c(1, 2, 3);    // 6

Use fn.length for arity. Don't worry about variadic functions.

expected time · O(arity) per partial
expected space · O(arity) collected args
4 lines
⏵ run · no run yet · ctrl+enter