File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -19,12 +19,13 @@ function calculateSumOfAllDigits(number) {
1919 . split ( "e" ) [ 0 ]
2020 . replaceAll ( "." , "" )
2121 . replaceAll ( "-" , "" ) ; //remove non digit characters to avoid errors
22- let sum = 0 ;
22+ let sum = 0 ; //initialize sum
2323 for ( let i = 0 ; i < numberString . length ; i ++ ) {
24- const digit = parseInt ( numberString [ i ] , 10 ) ;
25- sum += digit ;
24+ //repeat for each digit
25+ const digit = parseInt ( numberString [ i ] , 10 ) ; //convert string to integer
26+ sum += digit ; //add digit to sum
2627 }
27- return sum ;
28+ return sum ; //return sum of all digits
2829}
2930
3031function calculateSumOfIntegerDigits ( number ) {
@@ -33,12 +34,13 @@ function calculateSumOfIntegerDigits(number) {
3334 . toString ( )
3435 . replaceAll ( "." , "" )
3536 . replaceAll ( "-" , "" ) ; //remove non digit characters to avoid errors
36- let sum = 0 ;
37+ let sum = 0 ; //initialize sum
3738 for ( let i = 0 ; i < integerString . length ; i ++ ) {
38- const digit = parseInt ( integerString [ i ] , 10 ) ;
39- sum += digit ;
39+ //repeat for each digit
40+ const digit = parseInt ( integerString [ i ] , 10 ) ; //convert string to integer
41+ sum += digit ; //add digit to sum
4042 }
41- return sum ;
43+ return sum ; //return sum of integer digits
4244}
4345
4446function calculateSum ( number ) {
You can’t perform that action at this time.
0 commit comments