Created
November 30, 2020 23:50
-
-
Save gavinsykes/a3f17f6af2fa4f1de703c2604407d67e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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