Last active
August 29, 2015 14:01
-
-
Save knewter/be745ae2094dad324baa 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 WordStats do | |
def letter_frequency words do | |
words | |
|> Enum.reduce(%{}, fn(word, map) -> | |
word | |
|> String.graphemes | |
|> Enum.reduce(map, fn(letter, map) -> | |
Map.update(map, letter, 1, &(&1+1)) | |
end) | |
end) | |
end | |
end | |
defmodule TaskPlaygroundTest do | |
use ExUnit.Case | |
test "the truth" do | |
assert 1 + 1 == 2 | |
#words = File.read!("/usr/share/dict/words") |> String.split("\n") | |
words = [ | |
"cat", | |
"bag" | |
] | |
assert %{"c" => 1, "a" => 2, "t" => 1, "b" => 1, "g" => 1} == WordStats.letter_frequency(words) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment