Skip to content
Onsite

Curry

MediumP1Coding

Implement curry(fn).

It returns a curried version of fn. The curried function can be called with any number of arguments at a time; once the total number of arguments collected reaches fn.length, it calls fn with them and returns the result. Until then it returns another function that keeps collecting.

So curry(add3)(1)(2)(3), curry(add3)(1, 2)(3) and curry(add3)(1, 2, 3) all give the same result.

Example 1

Input
const add3 = (a, b, c) => a + b + c; curry(add3)(1)(2)(3)
Output
6

Example 2

Input
curry(add3)(1, 2)(3)
Output
6

Constraints

  • fn has a fixed number of parameters (no rest or default parameters)
  • 0 <= fn.length <= 10

Hints

Run checks the 3 visible tests, Submit all 8.