mirror of
https://github.com/rjNemo/exercism-elixir
synced 2026-06-06 02:16:48 +00:00
15 lines
463 B
Elixir
15 lines
463 B
Elixir
defmodule Anagram do
|
|
@doc """
|
|
Returns all candidates that are anagrams of, but not equal to, 'base'.
|
|
"""
|
|
@spec match(String.t(), [String.t()]) :: [String.t()]
|
|
def match(base, candidates),
|
|
do:
|
|
Enum.filter(
|
|
candidates,
|
|
&(String.downcase(&1) != String.downcase(base) and
|
|
to_graphemes(&1) == to_graphemes(base))
|
|
)
|
|
|
|
defp to_graphemes(string), do: String.downcase(string) |> String.graphemes() |> Enum.sort()
|
|
end
|