Skip to content

Instantly share code, notes, and snippets.

@Goloburda
Created November 26, 2019 08:07
Show Gist options
  • Save Goloburda/339140109b72d43eccdf8834371058da to your computer and use it in GitHub Desktop.
Save Goloburda/339140109b72d43eccdf8834371058da to your computer and use it in GitHub Desktop.
JavaScript call function n-times.
// 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