Fix syntax (using JavaScript Standard Style)

This commit is contained in:
Eric Lavault
2021-10-05 19:50:30 +02:00
parent 7027515475
commit 697c840cfa

View File

@ -11,21 +11,20 @@
* Find the sum of the digits in the number 100! * Find the sum of the digits in the number 100!
*/ */
const factorialDigitSum = function (n = 100) { const factorialDigitSum = (n = 100) => {
// Consider each digit*10^exp separately, right-to-left ([units, tens, ...]). // Consider each digit*10^exp separately, right-to-left ([units, tens, ...]).
let digits = [1]; const digits = [1]
for (let x = 2; x <= n; x++) { for (let x = 2; x <= n; x++) {
let carry = 0; let carry = 0
for (let exp = 0; exp < digits.length; exp++) { for (let exp = 0; exp < digits.length; exp++) {
const prod = digits[exp]*x + carry; const prod = digits[exp] * x + carry
carry = Math.floor(prod/10); carry = Math.floor(prod / 10)
digits[exp] = prod % 10; digits[exp] = prod % 10
} }
while (carry > 0) { while (carry > 0) {
digits.push(carry%10); digits.push(carry % 10)
carry = Math.floor(carry/10); carry = Math.floor(carry / 10)
} }
} }