17 lines
457 B
Elixir
17 lines
457 B
Elixir
|
defmodule ETL do
|
||
|
@doc """
|
||
|
Transform an index into an inverted index.
|
||
|
|
||
|
## Examples
|
||
|
|
||
|
iex> ETL.transform(%{"a" => ["ABILITY", "AARDVARK"], "b" => ["BALLAST", "BEAUTY"]})
|
||
|
%{"ability" => "a", "aardvark" => "a", "ballast" => "b", "beauty" =>"b"}
|
||
|
"""
|
||
|
@spec transform(map) :: map
|
||
|
def transform(input) do
|
||
|
Enum.reduce(input, %{}, fn {count, words}, acc ->
|
||
|
Enum.reduce(words, acc, &Map.put(&2, String.downcase(&1), count))
|
||
|
end)
|
||
|
end
|
||
|
end
|