Good day developers, i'm having issues figuring out how to make a function work.
Test case
test "count one of each" do
expected = %{"one" => 1, "of" => 1, "each" => 1}
assert Words.count("one of each") == expected
end
And this is what i came up with so far.
@spec count(String.t()) :: map
def count(sentence) do
sentence
|> String.split
|> Enum.map([sentence], &(%{sentence => 1 , value =>&1}))
end
end
The code itself doesn't work, can some one explain how can i achieve the following functionality based on the test i provided?
Big thanks.