DEV Community

Discussion on: Daily Challenge #205 - Consonant String Value

Collapse
 
avalander profile image
Avalander

Scala

  lazy val values = "abcdefghijklmnopqrstuvwxyz".toList.zip(Stream.from(1)).toMap

  def solve (str: String): Int = {
    ("[aeiou]".r.split(str).toList map evaluate).max
  }

  def evaluate (str: String): Int = {
    (str map (values.getOrElse(_, 0))).sum
  }

  solve("zodiacs")          // 26
  solve("chruschtschov")    // 80
  solve("khrushchev")       // 38
  solve("strength")         // 57
  solve("catchphrase")      // 73
  solve("twelfthstreet")    // 103
  solve("mischtschenkoana") // 80
Collapse
 
not_jffrydsr profile image
@nobody

I've always appreciated Scala solutions for their mixed-notation to function-call chaining, it's truly bizarre. 😲

...(str map ([expr]) // prefix-notation chaining...
...[expr]).sum // object-notation chaining...