AtomicScala / atomic-scala-corrections

Find out about or report corrections for the book "Atomic Scala"
http://www.atomicscala.com
6 stars 2 forks source link

Atom "Design by Contract", exercise 1 #82

Open waij opened 7 years ago

waij commented 7 years ago

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 commented 7 years ago

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

BruceEckel commented 7 years ago

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.