Skip to content

Commit 9b32db2

Browse files
authored
Update: Added Unary Operator in SumOfDigits algorithm (#1348)
* Update: Added Unary Operator in SumOfDigits algorithm * Update: Added Unary Operator in SumOfDigits algorithm
1 parent 53b1f66 commit 9b32db2

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Maths/SumOfDigits.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
/*
99
The given input is converted to a string, split into an array of characters.
1010
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.
1211
*/
1312
function sumOfDigitsUsingString (number) {
1413
if (number < 0) number = -number
1514

16-
return Number.parseInt(number.toString().split('').reduce((a, b) => Number(a) + Number(b)))
15+
return +(number.toString().split('').reduce((a, b) => (+a) + (+b)))
1716
}
1817

1918
/*

0 commit comments

Comments
 (0)