my-solutions/codewars/elixir/anagram/lib/anagram.ex

15 lines
321 B
Elixir
Raw Normal View History

defmodule Anagram do
@spec anagram?(a :: String.t(), b :: String.t()) :: boolean
def anagram?(a, b) do
Map.equal?(to_symbols(a), to_symbols(b))
end
@spec to_symbols(a :: String.t()) :: map()
defp to_symbols(a) do
a
|> String.downcase()
|> String.graphemes()
|> Enum.frequencies()
end
end