Created
March 6, 2019 20:28
-
-
Save CesarBMartinez/f9408945edf93deb2131502d438a9b01 to your computer and use it in GitHub Desktop.
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 (isNaN(n)) { | |
return NaN; | |
} | |
// If n is 0 or 1, returns 1 | |
let result = 1; | |
for (let i = 2; i <= n; i++) { | |
result = result * i; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment