Skip to content

Commit 2ad17b3

Browse files
authored
Merge pull request #495 from Waddah-JD/project-Euler-problem-020-solution
Project Euler problem 020 solution
2 parents 1bc6066 + 1538f41 commit 2ad17b3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Project-Euler/Problem020.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Factorial digit sum
3+
4+
n! means n × (n − 1) × ... × 3 × 2 × 1
5+
6+
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
7+
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
8+
9+
Find the sum of the digits in the number 100!
10+
*/
11+
12+
const findFactorialDigitSum = (num) => {
13+
let result = 0
14+
const stringifiedNumber = factorize(num).toLocaleString('fullwide', { useGrouping: false })
15+
stringifiedNumber.split('').map(num => { result += Number(num) })
16+
return result
17+
}
18+
19+
const factorize = (num) => num === 0 ? 1 : num * factorize(num - 1)
20+
21+
console.log(findFactorialDigitSum(100))

0 commit comments

Comments
 (0)