Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for negative numbers in digit_sum() #235

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ShatadalDas
Copy link

The function digit_sum() check if the number provided is integer or not. if not then check if the number is negative or not. if negative then make it positive and proceed for the sum.

Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be just num = Math.abs(num);. The doc comment would also need to be updated to say "an integer".

I don't think this is necessarily an improvement, though. It makes sense to only allow natural numbers. People can simply do digitSum(Math.abs(k)) if they want to apply it to negative numbers as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants