Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yclim95/cce3683906fff6aeb892 to your computer and use it in GitHub Desktop.
Save yclim95/cce3683906fff6aeb892 to your computer and use it in GitHub Desktop.
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")
@yclim95
Copy link
Author

yclim95 commented Jan 13, 2016

Why is adding the cannonical method a good idea?

  • is to break down the function for sorting each words to check whether both the words are identical

what principles in programming does it follows

  • Readability
  • Functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment