Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. defmodule StringsAndBinaries do
  2. def anagram?(word1, word2) do
  3. sortedWithoutSpaces1 = Enum.sort(word1) |> Enum.reject(fn(x) -> x === ' ' end)
  4. sortedWithoutSpaces2 = Enum.sort(word2) |> Enum.reject(fn(x) -> x === ' ' end)
  5. _anagram?(sortedWithoutSpaces1, sortedWithoutSpaces2, true)
  6. end
  7.  
  8. defp _anagram?([], [], value), do: value
  9. defp _anagram?(_, [], value), do: false
  10. defp _anagram?([], _, value), do: false
  11. defp _anagram?([word1H| word1Tail], [word2H| word2Tail], value), do: _anagram?(word1Tail, word2Tail, value && (word1H === word2H))
  12. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement