09 / 09

Implement a custom currying function.

javascript
Difficulty: 5/10
Topics: higher-order functions, partial application, function composition

Scenario Questions

0-2 years experience
  1. 1

    We have a simple function add(a, b) that returns a + b. How would you write a curried version so that add(2)(3) works?

  2. 2

    If you call your curried function with only the first argument and then later with the second, what does it return? Walk me through the steps.

  3. 3

    What happens if you pass three arguments to a curried version of a two‑parameter function?

2-5 years experience
  1. 1

    Our team refactored fetchData(url, options) to be curried, but some calls now throw 'undefined is not a function'. What could be causing this?

  2. 2

    Explain the trade‑offs between using a generic curry helper versus writing specific partially applied wrappers for each utility function.

  3. 3

    How would you adapt your curry implementation to handle functions with variable arity, like Math.max?

5-8 years experience
  1. 1

    Design a curry utility that can be used in a high‑throughput server handling thousands of requests per second. What performance considerations would you keep in mind?

  2. 2

    How would you ensure that your curried functions remain tree‑shakeable and don’t bloat the bundle size in a large front‑end app?

  3. 3

    When currying methods of a class, how do you preserve the correct this context?

8+ years experience
  1. 1

    Our organization is shifting toward a functional style. How would you plan the migration of existing utility functions to curried versions across multiple services while minimizing risk?

  2. 2

    What guidelines would you set for when to expose a function as curried in a shared library, considering maintainability and onboarding new engineers?

  3. 3

    If a legacy library’s custom curry implementation has memory‑leak issues, how would you decide between fixing it or replacing it, and what migration strategy would you propose?

Follow-up Questions

  • Can you show a quick example of using your curry with a two‑argument function?
  • What edge cases would you test for this implementation?
  • How would you modify it to preserve the original function's this binding?