Member-only story
Interview11: Curry function in JavaScript
Deep Dive into Curry function in Javascript
In this article, we are talking about Curry Functions, and how to implement the Curry Functions in Javascript.
Currying in JavaScript is a functional programming technique that breaks down a function that takes multiple arguments into a series of functions that each take a single argument.
f(a, b, c) // Normal Function
f(a)(b)(c) // Curry FunctionLetβs start with a simple curry function.
function curryFn (x) {
return function(y) {
return x + y;
}
}
console.log(curryFn(10)(20)); // Called twice with (10), with (20)What if we want to pass n number of params like curryFn(10)(20)(30)(40)?
Infinite Currying
write a curry function to accept n number of params
function curryFn (x) {
var inner = function (y) {
if(!y) return x;
x = x + y;
return inner;
}
return inner;
}
console.log(curryFn(10)(20)(30)(40)(100)());You may notice curryFn has been called with empty params in the last to identify the end of curryFn.










