implement curry()
JavaScript
easy
10 mins
Create a curry function that accepts a function fn and returns a curried version of it. The curried function should accept arguments one at a time, and once all arguments are received (based on the original function's arity), the original function should be executed.
Example Inputs & Outputs
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 curriedSum(1, 2, 3); // → 6
Constraints & Edge Cases
- The input
fncan have any number of parameters. - The curried function must handle partial application (passing fewer args in one call).
- It should support chaining until all arguments are passed.
- If
fntakes 0 arguments, it should return the result of callingfn().
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
