We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 53b1f66 commit 9b32db2Copy full SHA for 9b32db2
Maths/SumOfDigits.js
@@ -8,12 +8,11 @@
8
/*
9
The given input is converted to a string, split into an array of characters.
10
This array is reduced to a number using the method <Array>.reduce
11
- NOTE: The final parseInt is just there in cases where 1 digit numbers are given, since without that it would result in a String output.
12
*/
13
function sumOfDigitsUsingString (number) {
14
if (number < 0) number = -number
15
16
- return Number.parseInt(number.toString().split('').reduce((a, b) => Number(a) + Number(b)))
+ return +(number.toString().split('').reduce((a, b) => (+a) + (+b)))
17
}
18
19
0 commit comments