Skip to content

Instantly share code, notes, and snippets.

@IamManchanda
Created December 15, 2020 10:55
Show Gist options
  • Save IamManchanda/114bd743fdc67261740c3b0bd956661c to your computer and use it in GitHub Desktop.
Save IamManchanda/114bd743fdc67261740c3b0bd956661c to your computer and use it in GitHub Desktop.
Currying function in JavaScript
/**
* Currying function in JavaScript
*/
// Normal function definition
function multiply(a, b, c) {
return a * b * c;
}
multiply(1, 2, 3); // 👉 Output: 6
// Currying function definition
// const multiplyCurry = a => b => c => a * b * c;
// or, 👇
function multiplyCurry(a) {
return function (b) {
return function (c) {
return a * b * c;
};
};
}
multiplyCurry(1)(2)(3); // 👉 Output: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment