We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 1bc6066 + 1538f41 commit 2ad17b3Copy full SHA for 2ad17b3
Project-Euler/Problem020.js
@@ -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