Sha256: 3e84fadc4b0aa72ac5ca80ccf1083478ae42d8a94b1ee44d37a01954513d40d2

Contents?: true

Size: 515 Bytes

Versions: 322

Compression:

Stored size: 515 Bytes

Contents

module WordCount exposing (..)

import String
import Dict exposing (Dict)
import Regex


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

322 entries across 322 versions & 1 rubygems

Version Path
trackler-2.2.1.64 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.63 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.62 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.61 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.60 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.59 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.58 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.57 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.56 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.55 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.54 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.53 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.52 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.51 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.50 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.49 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.48 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.47 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.46 tracks/elm/exercises/word-count/WordCount.example.elm
trackler-2.2.1.45 tracks/elm/exercises/word-count/WordCount.example.elm