Curry Polyfill

FunctionalPolyfill

Implement curry(fn) that returns a curried version of fn.

Requirements:

  • Use fn.length to determine the target arity
  • Return a function that keeps accumulating arguments across calls
  • Invoke fn as soon as total collected arguments ≥ fn.length
  • Support any mix of arities per call: f(a)(b)(c), f(a,b)(c), f(a)(b,c)

Examples

Example 1
Input
const sum = (a, b, c) => a + b + c;
const c = curry(sum);
console.log(c(1)(2)(3));
console.log(c(1, 2)(3));
console.log(c(1)(2, 3));
Output
6
6
6
Explanation
All three calling styles produce the same result once three arguments are collected.

Notes

  • `fn.length` counts declared parameters — it does not count rest parameters (`...args`)

Hints

Read the full write-up for Curry Polyfill
</>JavaScript
Loading editor…
Test Result
Run your code, or Submit to test it