Created
January 21, 2020 14:44
-
-
Save hiwaldo89/acad12db1dc0336e7ee2b398f2318d52 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 isFactorial(n) { | |
let x = 0; | |
let counter = 0; | |
while (x <= n) { | |
x = getFactorial(counter); | |
if (x === n ) { | |
return true; | |
} | |
counter++; | |
} | |
return false; | |
} | |
function getFactorial(n) { | |
if (n >= 0) { | |
if (n === 0) { | |
return 1; | |
} | |
let x = n; | |
for (i = 1; i < n; i++) { | |
x = x * (n - i); | |
} | |
return x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment