exercism / scala

Exercism exercises in Scala.
https://exercism.org/tracks/scala
MIT License
123 stars 131 forks source link

Hamming approaches tweak #754

Closed bobahop closed 1 year ago

bobahop commented 1 year ago

Added the following text to the match and recursion approach:

A more idiomatic way to do the same thing as the substring() method calls is to use the head() and tail() methods. The head() method returns the first Char in the String, and the tail() method returns all of the Chars after the first Char, like so:

distanceCount(
  (if (s1.head != s2.head) acc + 1 else acc),
  s1.tail,
  s2.tail
)
bobahop commented 1 year ago

@ErikSchierboom: a small but idiomatic enhancement to the recursive explanation for Scala Hamming is ready for review.

ErikSchierboom commented 1 year ago

As you're saying this is more idiomatic, should this improved version be the version we show in the introduction/snippet/top of the approach?

bobahop commented 1 year ago

Yes, I think you're right. Let me get rid of the substring stuff altogether...

bobahop commented 1 year ago

@ErikSchierboom: Edits made for Hamming. Ready for review and hopefully merge. Still waiting on one other exercise to churn through Scala / Test / ci...