Sha256: 3a45b1dd358e947af08ed977ac9b6b3eb062f01cac4e30fb32f1ab2b84486a36

Contents?: true

Size: 520 Bytes

Versions: 66

Compression:

Stored size: 520 Bytes

Contents

module WordCount exposing (wordCount)

import Dict exposing (Dict)
import Regex
import String


wordCount : String -> Dict String Int
wordCount sentence =
    sentence
        |> String.toLower
        |> depunctuate
        |> String.words
        |> List.foldl (\w d -> Dict.update w incrMaybe d) Dict.empty


depunctuate : String -> String
depunctuate =
    Regex.replace Regex.All (Regex.regex "[^a-z0-9 ]") (\_ -> "")


incrMaybe : Maybe Int -> Maybe Int
incrMaybe maybe =
    Maybe.withDefault 0 maybe + 1 |> Just

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.179 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.178 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.177 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.176 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.175 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.174 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.173 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.172 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.171 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.170 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.169 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.167 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.166 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.165 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.164 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.163 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.162 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.161 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.160 tracks/elm/exercises/word-count/WordCount.example.elm