Sha256: 65e16ebc824e75ef796215386b472a88bd11fabf31b45349a615db2bc88f056e

Contents?: true

Size: 418 Bytes

Versions: 126

Compression:

Stored size: 418 Bytes

Contents

object WordCount {

    fun phrase(phrase: String): Map<String, Int> {
        val withoutPunctuation = phrase.toLowerCase().replace(Regex("[^\\w']"), " ").trim()

        val words = withoutPunctuation.split(Regex("\\s+"))

        val unquotedWords = words.map { word -> word.trim('\'') }

        val groupedWords = unquotedWords.groupBy { w -> w }

        return groupedWords.mapValues { it.value.size }
    }

}

Version data entries

126 entries across 126 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.138 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.137 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.136 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.135 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.134 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.133 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.132 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.131 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.130 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.129 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.128 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.127 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.126 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.125 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.124 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.123 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.122 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.121 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt
trackler-2.2.1.120 tracks/kotlin/exercises/word-count/.meta/src/reference/kotlin/WordCount.kt