Created
October 17, 2019 01:36
-
-
Save CharlesRajendran/24f80e492cf9f52baac67119bfd4ccaa to your computer and use it in GitHub Desktop.
recursively calling method chaining [ sum(1)(2)(3)(4)(7)() ]
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 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