Last active
September 13, 2015 17:08
-
-
Save softwarespot/c8a66029a09b13759dc8 to your computer and use it in GitHub Desktop.
Recursive sum function inside an IIFE. (Not my idea!) Uses ES2015 syntax.
This file contains hidden or 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
// 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