Created
October 25, 2013 18:08
-
-
Save mosampaio/7159186 to your computer and use it in GitHub Desktop.
Recursive factorial in Javascirpt
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
var factorial = function factorial_i(n) { | |
return (n > 1) ? n * factorial_i(n-1) : n; | |
}; | |
console.log(factorial(1)); //1 | |
console.log(factorial(2)); //2 | |
console.log(factorial(3)); //6 | |
console.log(factorial(4)); //24 | |
console.log(factorial(5)); //120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment