Currying Technique
THEORY CONCEPT
- English: Currying is when you break down a function that takes multiple arguments into a series of functions that take part of the arguments.
- Việt Ngữ: Currying là kỹ thuật phân rã hàm nhiều tham số thành series hàm nhận vào 1 hoặc nhiều tham số từ tập hơp tham số ban đầu.
CONCEPT CODE
Normal
1
2
3
4
5
6
7
8//sum in normal
function sum(a, b){
return a + b;
}
//-Arrow-
var sum = (a, b) => a + b;
//
call sum(1, 2);Use currying
1
2
3
4
5
6
7
8
9
10//Sum with currying
function sum(a){
return function(b){
return a + b
}
}
//-Arrow-
var sum a => b => a + b;
//call
sum(1)(2);
DEMO
1 | const arr = [ |