From f076de3d1128f93b0a0d64d233d8770db83b2f20 Mon Sep 17 00:00:00 2001 From: ShatadalDas Date: Thu, 21 Mar 2024 21:44:05 +0530 Subject: [PATCH 1/2] add support for negative integers as well --- maths/digit_sum.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/maths/digit_sum.ts b/maths/digit_sum.ts index 34be6730..59a10739 100644 --- a/maths/digit_sum.ts +++ b/maths/digit_sum.ts @@ -9,8 +9,12 @@ */ export const digitSum = (num: number): number => { - if (num < 0 || !Number.isInteger(num)) { - throw new Error('only natural numbers are supported') + if (!Number.isInteger(num)) { + throw new Error('only integers are supported') + } + + if(num < 0) { + num *= -1; } let sum = 0 @@ -21,3 +25,6 @@ export const digitSum = (num: number): number => { return sum } + + +console.log(digitSum(-4567)) From bbdd895f6ba30b1ce3ab4ca190b409fe6d48e1b0 Mon Sep 17 00:00:00 2001 From: ShatadalDas Date: Thu, 21 Mar 2024 21:45:42 +0530 Subject: [PATCH 2/2] remove console.log() --- maths/digit_sum.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/maths/digit_sum.ts b/maths/digit_sum.ts index 59a10739..39724081 100644 --- a/maths/digit_sum.ts +++ b/maths/digit_sum.ts @@ -25,6 +25,3 @@ export const digitSum = (num: number): number => { return sum } - - -console.log(digitSum(-4567)) 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