Read here. Code on desktop. The coding workspace opens on screens 1024px and wider.
JavaScript interview question
Curry
medium20 min
Implement curry to convert a multi-argument function into a chain of unary calls.
Requirements
Export curry as named and default. Use fn.length as the required argument count and return a reusable chain of unary functions.
For an arity of n > 0, collect one argument per call and invoke fn only on the nth call. Explicit undefined counts as an argument.
For a zero-argument function, invoke fn on the first call to its curried wrapper. Do not invoke fn while currying.
Each partial application can be reused independently. Preserve argument order and use the this value of the final call when invoking fn.
Return the exact result and propagate errors when fn is invoked. Default/rest parameters, grouped calls, placeholders, and constructing with new are out of scope.
Examples
Example 1
Input: const add = curry((a, b, c) => a + b + c);
add(1)(2)(3);
Output: 6