Anagram koan
defmodule Anagram do | |
@doc """ | |
# Anagram | |
Given a word and a list of possible anagrams, selects the correct one(s). | |
## Example | |
iex> Anagram.match "listen",%w(enlists google inlets banana) | |
["inlets"] | |
""" | |
def match(word,words) do | |
normalized_word = normalize_word(word) | |
Enum.filter words, fn x -> normalized_word==normalize_word(x) end | |
end | |
defp normalize_word(word) do | |
word |> String.codepoints |> Enum.sort | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment