Given the following Map("DIAMOND" -> "DAYMAHND", "THOUSAND" -> "THAWZAHND"), I want to take the value of each item in the current map and update those values in a new map with the last vowel and every other word after it as values and the same word as keys. How would I do this in Scala? I heard of people accomplishing this by using .stripSuffix(). (Maps are immutable)
Input: Map("DIAMOND" -> "DAYMAHND", "THOUSAND" -> "THAWZAHND")
Output: Map("DIAMOND" -> "AHND", "THOUSAND" -> "AHND")
My Attempt:
val table1 = Map("DIAMOND" -> "DAYMAHND", "THOUSAND" -> "THAWZAHND")
val table2 = table1.map { case (key, value) =>
val string_2 = value
.reverse
.takeWhile("AEIOU".indexOf(_) ==
-1)
(key, string_2 + value.charAt(value.length
- 1 - string_2.length))
}
.toMap