Last active
March 28, 2016 18:55
-
-
Save sheminusminus/cbab23c3718b229f3b9c to your computer and use it in GitHub Desktop.
factorial
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
function factorial(n) { | |
if (n < 0 || typeof n != 'number') | |
{ return null; } | |
if (n === 0) | |
{ return 1;} | |
for (var i = n - 1; i > 0; i--) | |
{ n *= i; } | |
return n; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment