Created
December 15, 2020 10:55
-
-
Save IamManchanda/114bd743fdc67261740c3b0bd956661c to your computer and use it in GitHub Desktop.
Currying function in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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