Skip to content

Instantly share code, notes, and snippets.

@softwarespot
Last active September 13, 2015 17:08
Show Gist options
  • Save softwarespot/c8a66029a09b13759dc8 to your computer and use it in GitHub Desktop.
Save softwarespot/c8a66029a09b13759dc8 to your computer and use it in GitHub Desktop.
Recursive sum function inside an IIFE. (Not my idea!) Uses ES2015 syntax.
// Recursive sum function inside an IIFE. (Not my idea!)
(() => {
main();
function main() {
console.write(sum(10));
}
function sum(n) {
if (n === 1) {
return 1;
}
return n + sum(n - 1);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment