Skip to content

Instantly share code, notes, and snippets.

@abhinavnigam2207
Created March 5, 2019 11:11
Show Gist options
  • Save abhinavnigam2207/d39e247bbcdd4fd4c7049581d48b074e to your computer and use it in GitHub Desktop.
Save abhinavnigam2207/d39e247bbcdd4fd4c7049581d48b074e to your computer and use it in GitHub Desktop.
Make the syntax work sum(1)(2)(3).......() [Asked in multiple interviews]
function sum(a) {
return function(b) {
if(b){
return sum(a+b);
}
return a;
}
}
/* ES 6 Version of the code */
// sum => a => b => b ? sum(a+b) : a;
sum(1)(2)(3)(4)(5)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment