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

22246 Provide #digitSum in Integer + tests #1628

Conversation

astares
Copy link
Member

@astares astares commented Jul 3, 2018

Copy link
Contributor

@SergeStinckwich SergeStinckwich left a comment

Choose a reason for hiding this comment

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

I agree with the changes, but do we need such a method ?

@astares
Copy link
Member Author

astares commented Jul 4, 2018

We do not directly need it to run our image - but we have other methods that are also not
directly needed but good to have.

I would add it as

  • it is useful for easy verification when number have to be entered (as an additional checksum)
  • I often use it to demonstrate what one can easily do with Smalltalk
    (it is a good example to understand #inject:into and one can apply it to very large numbers
    which is not possible in most other languages)

"Returns the digit sum of the receiver"

^self asString inject: 0 into: [:value :new| value + new digitValue]
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

returns bad values for negative numbers (like 8 for -9)

@Ducasse Ducasse merged commit 87fa773 into pharo-project:development Jul 13, 2018
@Ducasse
Copy link
Member

Ducasse commented Jul 13, 2018

It would be good to have

"1234 digitSum >>> 10"

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

4 participants