File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed
Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change 1111 * Find the sum of the digits in the number 100!
1212 */
1313
14- const factorialDigitSum = function ( n = 100 ) {
15-
14+ const factorialDigitSum = ( n = 100 ) => {
1615 // Consider each digit*10^exp separately, right-to-left ([units, tens, ...]).
17- let digits = [ 1 ] ;
16+ const digits = [ 1 ]
1817
19- for ( let x = 2 ; x <= n ; x ++ ) {
20- let carry = 0 ;
21- for ( let exp = 0 ; exp < digits . length ; exp ++ ) {
22- const prod = digits [ exp ] * x + carry ;
23- carry = Math . floor ( prod / 10 ) ;
24- digits [ exp ] = prod % 10 ;
18+ for ( let x = 2 ; x <= n ; x ++ ) {
19+ let carry = 0
20+ for ( let exp = 0 ; exp < digits . length ; exp ++ ) {
21+ const prod = digits [ exp ] * x + carry
22+ carry = Math . floor ( prod / 10 )
23+ digits [ exp ] = prod % 10
2524 }
2625 while ( carry > 0 ) {
27- digits . push ( carry % 10 ) ;
28- carry = Math . floor ( carry / 10 ) ;
26+ digits . push ( carry % 10 )
27+ carry = Math . floor ( carry / 10 )
2928 }
3029 }
3130
You can’t perform that action at this time.
0 commit comments