Created
March 9, 2015 21:02
-
-
Save mrcnkoba/e00033308289b998ac4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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