Skip to the solution
HardFrontend6 min read

What is currying?

563 views

The problem

Question presented to candidate: "What is currying, and can you show me how you'd write a generic curry() helper that works for any function, regardless of how many arguments it takes?"

What a strong answer should cover:

  • πŸ“Œ Interview term: currying β€” transforming a function that takes multiple arguments into a sequence of functions, each taking a single argument (or a subset), where calling with fewer than all the needed arguments returns a new function waiting for the rest.
  • πŸ“Œ Interview term: the real, direct answer to the prompt β€” verified directly: a generic curry(fn) helper genuinely worked correctly across three different calling patterns for the same 3-argument function β€” all-at-once (curriedAdd3(1, 2, 3)), one-then-two (curriedAdd3(1)(2, 3)), and fully split (curriedAdd3(1)(2)(3)) β€” all producing the identical, correct real result.
  • πŸ“Œ Interview term: partial application β€” currying's most common real, practical payoff: calling a curried function with FEWER than all its arguments produces a new, reusable, "pre-configured" function β€” verified directly with a real tax-calculation example, where partially applying just the tax rate produced a genuinely reusable function correctly applied to multiple different prices.
  • A precise answer names fn.length as the real mechanism most generic curry implementations use to know how many arguments to wait for before actually invoking the original function β€” a precise, verified detail beyond just describing the general idea.
  • A precise answer distinguishes currying from simple partial application via bind: bind pre-fills a fixed number of leading arguments once; a curried function genuinely supports being called with any split of arguments across any number of calls, not just one fixed split.

Clarifying questions expected:

  • None β€” this is a definitional/technical question; producing a real, working generic curry implementation (not just a hard-coded 2-argument example) is the strong signal.

Code / implementation expected: Yes β€” a real, generic curry() helper verified to work across multiple calling patterns for the same function is the clearest, most convincing demonstration.

  • currying

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 Β· 8 sections

Run the code

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

JavaScriptA real, generic curry() helper verified across multiple argument-splitting patterns, plus a real partial-application example

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 144 of 165 in JavaScript

Keep your momentum going.

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

Up nextHard

How do you implement a custom Promise.any polyfill?

Continue