Skip to content

Instantly share code, notes, and snippets.

@hiwaldo89
Created January 21, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiwaldo89/acad12db1dc0336e7ee2b398f2318d52 to your computer and use it in GitHub Desktop.
Save hiwaldo89/acad12db1dc0336e7ee2b398f2318d52 to your computer and use it in GitHub Desktop.
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