tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt in trackler-2.2.1.52 vs tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt in trackler-2.2.1.53
- old
+ new
@@ -1,11 +1,15 @@
object WordCount {
fun phrase(phrase: String): Map<String, Int> {
val withoutPunctuation = phrase.toLowerCase().replace(Regex("[^\\w']"), " ").trim()
+
val words = withoutPunctuation.split(Regex("\\s+"))
- val groupedWords = words.groupBy({ w -> w })
- return groupedWords.mapValues({ it.value.size })
+ val unquotedWords = words.map { word -> word.trim('\'') }
+
+ val groupedWords = unquotedWords.groupBy { w -> w }
+
+ return groupedWords.mapValues { it.value.size }
}
}