Javascript Currying
Transform a function with multiple parameters into calling a nesting function multiple times with one parameter; the functionality of the two situations is not changed.
For example, the following functions have the same functionality but different formats:
// original format
function add(a, b) {
return a + b;
}
// currying format
function curryingAddFirst(a) {
return function (b) {
return a + b;
};
}
// currying format with arrow function
const curryingAddSecond = (a) => (b) => a + b;
Comments
Post a Comment