FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Hard

Curry III

35mins

Implement a function curry(fn) that transforms a function taking multiple arguments into a function that can be called repeatedly with any number of arguments until all required arguments are provided.

The function should:

  • Accept a function fn with a fixed number of parameters.
  • Return a curried version of the function.
  • Allow partial application with any number of arguments.
  • Return the final result when the total number of provided arguments reaches the original function's arity.

Example

function sum(a, b, c) { return a + b + c; } const curriedSum = curry(sum); curriedSum(1)(2)(3); // 6 curriedSum(1, 2)(3); // 6 curriedSum(1)(2, 3); // 6

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests