//Currying:
It is a technique in functional programming, transformation of the
function of multiple arguments into several functions of a single
argument in sequence. It is also called nested function is ecmascript
//Without currying
function calculateVolume(length, breadth, height) {
return length * breadth * height;
}
//With Currying
function calculateVolume(length) {
return function (breadth) {
return function (height) {
return length * breadth * height;
}
}
}
//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
// It is also called nested function is ecmascript
const multiply = (a) => (b) => a*b;
multiply(3)(4); //Answer is 12
const multipleBy5 = multiply(5);
multipleBy5(10); //Answer is 50
It is a technique in functional programming, transformation of the
function of multiple arguments into several functions of a single
argument in sequence. It is also called nested function is ecmascript
//Without currying
function calculateVolume(length, breadth, height) {
return length * breadth * height;
}
//With Currying
function calculateVolume(length) {
return function (breadth) {
return function (height) {
return length * breadth * height;
}
}
}