Created
January 29, 2017 00:48
-
-
Save lagoushque/d514e9dd134978e4bdcd601bd0e1cf38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Words do | |
@doc """ | |
Count the number of words in the sentence. | |
Words are compared case-insensitively. | |
""" | |
@spec count(String.t) :: map | |
def count(sentence) do | |
String.split(String.downcase(sentence), ~r/[^[:alnum:]\-]+/u, trim: true) | |
|>Enum.reduce(%{}, fn(tag, acc) -> Map.update(acc, tag, 1, &(&1+1))end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment