Skip to content

Instantly share code, notes, and snippets.

@vijayjangid
Created June 15, 2019 06:47
Show Gist options
  • Save vijayjangid/481cc8b7affed8f946eee059295e6cec to your computer and use it in GitHub Desktop.
Save vijayjangid/481cc8b7affed8f946eee059295e6cec to your computer and use it in GitHub Desktop.
infinite curried function for sum
function f (input, sum = 0) {
if(!input) {
return sum;
}
else {
return function(nextInput) {
sum += input;
return f(nextInput, sum);
}
}
}
// example
/*
f(); // 0
f(1)(); // 1
f(1)(2)(3)(); // 6
f(3)(2)(5)(6)(); // 16
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment