Skip to content
Onsite

Curry with Placeholders

HardP3Coding

Implement curry(fn), which turns a function into a curried one that accepts its arguments in several calls, with placeholder support.

  • The curried function can be called with any number of arguments at a time. As soon as enough arguments have been collected (at least fn.length, and none of the first fn.length is a placeholder), it calls fn with all collected arguments and returns the result. Until then it returns a new function that keeps collecting.
  • curry.placeholder is a unique value that marks a skipped argument. A placeholder in a call reserves that position; later arguments fill the earliest reserved positions first, and only then are appended.
  • Partial applications are reusable: calling a returned function twice with different arguments must not interfere.
  • this of the final call is passed to fn.

Example 1

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

Constraints

  • 0 <= fn.length <= 10
  • Arguments can be any values except the placeholder itself.

Hints

Run checks the 3 visible tests, Submit all 11.