Skip to content

Instantly share code, notes, and snippets.

@CesarBMartinez
Created March 6, 2019 20:28
Show Gist options
  • Save CesarBMartinez/f9408945edf93deb2131502d438a9b01 to your computer and use it in GitHub Desktop.
Save CesarBMartinez/f9408945edf93deb2131502d438a9b01 to your computer and use it in GitHub Desktop.
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