Skip to content

Instantly share code, notes, and snippets.

@RANUX
Last active March 5, 2016 13:49
Show Gist options
  • Save RANUX/f910bef1d5e001389724 to your computer and use it in GitHub Desktop.
Save RANUX/f910bef1d5e001389724 to your computer and use it in GitHub Desktop.
Simple recursion examples on javascript
// 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