Currying
Currying is a technique of transforming a function that takes multiple arguments into a sequence of functions, each taking a single argument and returning another function (until all arguments have been provided).
In simpler words: Currying breaks down a function of n arguments into n functions that each take one argument.
Example Without Currying:
function add(a, b, c) {
return a + b + c;
}
console.log(add(1, 2, 3)); // Output: 6
Curried Version:
function curriedAdd(a) {
return function (b) {
return function (c) {
return a + b + c;
};
};
}
console.log(curriedAdd(1)(2)(3)); // Output: 6