currying vs multiple arguments code example
Example 1: currying in javascript
//No currying
function volume(w, h, l) {
return w * h * l;
}
volume(4, 6, 3); // 72
//Currying
function volume(w) {
return function(h) {
return function(l) {
return w * h* l;
}
}
}
volume(4)(6)(3); // 72
Example 2: what is a curried function
Curried Function
// Non-curried
function add(a, b, c) {
return a + b + c
}
add(1, 2, 3)
//-> 6
// Curried
function addd(a) {
return function (b) {
return function (c) {
return a + b + c
}
}
}
addd(1)(2)(3)
//-> 6