Created
November 26, 2019 08:07
-
-
Save Goloburda/339140109b72d43eccdf8834371058da to your computer and use it in GitHub Desktop.
JavaScript call function n-times.
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
// Function calls n-times before get '()'; | |
const closureFn = firstArgument => { | |
let sum = firstArgument; | |
return function callMe(nextArgument) { | |
if (nextArgument) { | |
sum += nextArgument; | |
return callMe; | |
} | |
return sum; | |
}; | |
}; | |
const result = closureFn(5)(6)(1)(11)(17)(-3)(); | |
console.log(result); // 37 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment