From 937b2cef5c719e44dfd6ca730e8f24bea600bec4 Mon Sep 17 00:00:00 2001 From: Chetan Nada <83969719+chetannada@users.noreply.github.com> Date: Sun, 13 Aug 2023 22:20:18 +0530 Subject: [PATCH 1/2] Update: Added Unary Operator in SumOfDigits algorithm --- Maths/SumOfDigits.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Maths/SumOfDigits.js b/Maths/SumOfDigits.js index e076be7a56..70df79b349 100644 --- a/Maths/SumOfDigits.js +++ b/Maths/SumOfDigits.js @@ -8,12 +8,12 @@ /* 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. + NOTE: The Unary Operator (+) is used here for converting String to Number 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))) } /* From d789633518ce605f12cd75adbf4cff619502e4a5 Mon Sep 17 00:00:00 2001 From: Chetan Nada <83969719+chetannada@users.noreply.github.com> Date: Mon, 14 Aug 2023 20:45:13 +0530 Subject: [PATCH 2/2] Update: Added Unary Operator in SumOfDigits algorithm --- Maths/SumOfDigits.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Maths/SumOfDigits.js b/Maths/SumOfDigits.js index 70df79b349..4b1d7264bc 100644 --- a/Maths/SumOfDigits.js +++ b/Maths/SumOfDigits.js @@ -8,7 +8,6 @@ /* 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 Unary Operator (+) is used here for converting String to Number since without that it would result in a String output. */ function sumOfDigitsUsingString (number) { if (number < 0) number = -number pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy