Last active
September 13, 2015 17:07
-
-
Save softwarespot/5d3ac94ac18c63f9ae25 to your computer and use it in GitHub Desktop.
Recursive sum function inside an IIFE. (Not my idea!) Uses ES5 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!) | |
(function () { | |
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