Last active
March 5, 2016 13:49
-
-
Save RANUX/f910bef1d5e001389724 to your computer and use it in GitHub Desktop.
Simple recursion examples on javascript
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
// factorials | |
function factorial(n) { | |
if ( n == 0 ) return 1; | |
return n * factorial( n - 1 ); | |
} | |
// triangle numbers | |
function triangle(n) { | |
if ( n == 1 ) return 1; | |
return n + triangle(n-1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment