Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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