Partial Application with Placeholders
Write the code, see it run, pass the checks.
The problem
- medium
- Code
- Pro
Export a placeholder value _ (any unique value, such as a Symbol) and write partial(fn, ...preset). It returns a function that calls fn and returns its result. The arguments fn gets are the preset ones, where each _ is filled in turn by the next argument of the call, followed by any call arguments left over. A placeholder with no call argument left becomes undefined. Every call starts afresh from the preset arguments.
Your code must pass
- Puts the preset arguments first
- Fills each placeholder with the call's arguments in order
- Adds leftover arguments at the end and leaves missing ones undefined
- Starts afresh from the preset arguments on every call