Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement