Last active
January 13, 2016 02:06
-
-
Save yclim95/cce3683906fff6aeb892 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
def canonical(word) | |
# MAgic goes here | |
# Downcase, then group & replace it Then split it ... lastly sort it | |
word.downcase.gsub(/[^a-z]+/).sort | |
end | |
def is_anagram?(word1, word2) | |
canonical(word1)==canonical(word2) | |
end | |
is_anagram?("abcde2","c2abed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is adding the cannonical method a good idea?
what principles in programming does it follows