1//No currying
2function volume(w, h, l) {
3 return w * h * l;
4}
5
6volume(4, 6, 3); // 72
7
8//Currying
9function volume(w) {
10 return function(h) {
11 return function(l) {
12 return w * h* l;
13 }
14 }
15}
16
17volume(4)(6)(3); // 72
1a technique that applies a function
2to its arguments one at a time, with
3each application returning a new function
4that accepts the next argument.
1// It is also called nested function is ecmascript
2const multiply = (a) => (b) => a*b;
3multiply(3)(4); //Answer is 12
4
5const multipleBy5 = multiply(5);
6multipleBy5(10); //Answer is 50
1Uses of currying function
2 a) It helps to avoid passing same variable again and again.
3
4 b) It is extremely useful in event handling.
5
6syntax:
7
8 function Myfunction(a) {
9 return (b) => {
10 return (c) => {
11 return a * b * c
12 }
13 }
14 }
15
16
17myFunction(1)(2)(3);
1Uses of currying function
2 a) It helps to avoid passing same variable again and again.
3
4 b) It is extremely useful in event handling.
5
6syntax:
7
8 function Myfunction(a) {
9 return (b) => {
10 return (c) => {
11 return a * b * c
12 }
13 }
14 }