From 9b32db29d880f689d9cafa9c258d29e30bf39294 Mon Sep 17 00:00:00 2001 From: Chetan Nada <83969719+chetannada@users.noreply.github.com> Date: Tue, 15 Aug 2023 01:24:00 +0530 Subject: [PATCH] Update: Added Unary Operator in SumOfDigits algorithm (#1348) * Update: Added Unary Operator in SumOfDigits algorithm * Update: Added Unary Operator in SumOfDigits algorithm --- Maths/SumOfDigits.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Maths/SumOfDigits.js b/Maths/SumOfDigits.js index e076be7a5..4b1d7264b 100644 --- a/Maths/SumOfDigits.js +++ b/Maths/SumOfDigits.js @@ -8,12 +8,11 @@ /* The given input is converted to a string, split into an array of characters. This array is reduced to a number using the method .reduce - 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. */ function sumOfDigitsUsingString (number) { if (number < 0) number = -number - return Number.parseInt(number.toString().split('').reduce((a, b) => Number(a) + Number(b))) + return +(number.toString().split('').reduce((a, b) => (+a) + (+b))) } /*