Skip to content

Instantly share code, notes, and snippets.

@mrcnkoba
Created March 9, 2015 21:02
Show Gist options
  • Save mrcnkoba/e00033308289b998ac4e to your computer and use it in GitHub Desktop.
Save mrcnkoba/e00033308289b998ac4e to your computer and use it in GitHub Desktop.
defmodule StringsAndBinaries do
def anagram?(word1, word2) do
sortedWithoutSpaces1 = Enum.sort(word1) |> Enum.reject(fn(x) -> x === ' ' end)
sortedWithoutSpaces2 = Enum.sort(word2) |> Enum.reject(fn(x) -> x === ' ' end)
_anagram?(sortedWithoutSpaces1, sortedWithoutSpaces2, true)
end
defp _anagram?([], [], value), do: value
defp _anagram?(_, [], value), do: false
defp _anagram?([], _, value), do: false
defp _anagram?([word1H| word1Tail], [word2H| word2Tail], value), do: _anagram?(word1Tail, word2Tail, value && (word1H === word2H))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment