currying functions javascript code example
Example 1: currying in javascript
function volume(w, h, l) {
return w * h * l;
}
volume(4, 6, 3);
function volume(w) {
return function(h) {
return function(l) {
return w * h* l;
}
}
}
volume(4)(6)(3);
Example 2: what is currying
a technique that applies a function
to its arguments one at a time, with
each application returning a new function
that accepts the next argument.
Example 3: what is a curried function
Curried Function
function add(a, b, c) {
return a + b + c
}
add(1, 2, 3)
function addd(a) {
return function (b) {
return function (c) {
return a + b + c
}
}
}
addd(1)(2)(3)