Skip to content

Instantly share code, notes, and snippets.

@CharlesRajendran
Created October 17, 2019 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlesRajendran/24f80e492cf9f52baac67119bfd4ccaa to your computer and use it in GitHub Desktop.
Save CharlesRajendran/24f80e492cf9f52baac67119bfd4ccaa to your computer and use it in GitHub Desktop.
recursively calling method chaining [ sum(1)(2)(3)(4)(7)() ]
function sum(num) {
return function(b) {
if (b) {
return sum(num+b);
} else {
return num;
}
}
}
// ES 6 Way
const sum2 = num1 => num2 => num2 ? sum2(num1+num2): num1;
const total = sum(1)(2)(3)(4)(7)();
console.log(total);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment