Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kirkins
Last active July 4, 2019 19:32
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 kirkins/c5c323a376dafd4920944563d9c21bc4 to your computer and use it in GitHub Desktop.
Save kirkins/c5c323a376dafd4920944563d9c21bc4 to your computer and use it in GitHub Desktop.
Euler Problem #20 in JS
// factorial
f = (n) => {
n = BigInt(n);
return (n>1) ? n * f(n-1n) : n;
}
// sum of digits in the number
s = (n) => {
return n.toString().split("")
.map(x => parseInt(x))
.reduce((a, b) => a+b);
}
console.log(s(f(100)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment