Skip to the solution
MediumDSA7 min read

Implement curry(func) with placeholder support

663 views

The problem

Problem, as an interviewer would state it: "Implement curry(fn) with PLACEHOLDER support — allowing a special _ placeholder value to reserve an argument's position for a LATER call, matching lodash's own well-known _.curry's placeholder behavior."

Examples:

Code
const curried = curry((a,b,c) => a+b+c);
curried(1, _, 3)(2); // 6 -- the placeholder's slot is filled by the LATER call

Clarifying questions expected:

  • What should the placeholder's own identity be — a real, unique Symbol, or a simpler sentinel like a string?
  • If MULTIPLE placeholders exist in one call, does the next call's own arguments need to fill them in order?
  • Does this still need to support a normal, placeholder-free call pattern, working identically to a simpler curry?

Code / implementation expected: Yes — real, direct proof of a placeholder correctly reserving a later slot in several different real positions, plus confirmation a normal, placeholder-free call still works identically.

  • curry
  • closure
  • partial-application

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

7 min read · 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal, direct proof: curry with placeholder support correctly fills a reserved argument slot across four distinct real placement patterns, plus a normal placeholder-free call

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 106 of 154 in JavaScript coding

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

Implement _.chunk(array, size)

Continue