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

Atom "Design by Contract", exercise 1 #82

Open
waij opened this issue Dec 26, 2016 · 2 comments
Open

Atom "Design by Contract", exercise 1 #82

waij opened this issue Dec 26, 2016 · 2 comments

Comments

@waij
Copy link

waij commented Dec 26, 2016

In the solution of exercise 1 of atom Design by Contract, you use foldLeft which you don't cover in your book (<shouty mode/>: DON'T DO THAT!). I suggest using:
def sumDigits(s:String):Int= s.map( c => c.asDigit ).reduce( (result,i) => i + result)

@waij
Copy link
Author

waij commented Dec 26, 2016

def sumDigits(s:String):Int= s.map( c => c.asDigit ).sum

@BruceEckel
Copy link
Member

Wanted to let you know I appreciate all your comments and will (eventually) address them all. I've been working on another book for the last couple of years and have a couple of other projects piled up so it could be awhile. But I've noticed the activity and appreciate your contributions.

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

No branches or pull requests

2 participants