Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created November 30, 2020 23:50
Show Gist options
  • Save gavinsykes/a3f17f6af2fa4f1de703c2604407d67e to your computer and use it in GitHub Desktop.
Save gavinsykes/a3f17f6af2fa4f1de703c2604407d67e to your computer and use it in GitHub Desktop.
const factorial = n => {
let res = n;
if (!Number.isInteger(n) || n < 0) {
return undefined;
}
if (n === 0 || n === 1)
return 1;
while (n > 1) {
n--;
result *= n;
}
return result;
};
const euler_20 = n => {
return factorial(n).toString().split('').reduce((acc,c) => acc += +c,0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment