Skip to the solution
EasyDSAAsked in 20246 min read

Partial application bindings

906 views

The problem

Problem, as an interviewer would state it: "Implement partial(fn, ...presetArgs) — returning a genuinely NEW function that, when LATER called, invokes fn with the preset arguments prepended to whatever new arguments the later call provides."

Examples:

Code
function add3(a, b, c) { return a + b + c; }
const addTo5 = partial(add3, 5);
addTo5(2, 3); // 10

Clarifying questions expected:

  • Does this need to support pre-filling MORE than one leading argument, not just the first?
  • Should the ORIGINAL function remain genuinely unaffected/reusable after calling partial() on it?
  • How does this genuinely differ from bind() — is partial application a distinct, real concept, or just a simplified bind?

Code / implementation expected: Yes — real, direct proof pre-filling both a single and multiple leading arguments, confirming the original function is genuinely unaffected and reusable afterward.

  • js-coding
  • utility
  • algorithm

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

6 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: partial() correctly pre-fills leading arguments, leaving the original function genuinely unaffected and independently reusable afterward

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 25 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 nextEasy

Implement Promise.race()

Continue