Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yclim95/93c246fdc02f199b3532 to your computer and use it in GitHub Desktop.
Save yclim95/93c246fdc02f199b3532 to your computer and use it in GitHub Desktop.
# Define function
#/ 1.Ask for input
# 2.Check the length of words
# 2.1 return false if length !=
# 2.2 string.length==string2.length
# 3. Check for capitalization
# string.downcase
# 4. Break the word into individual Array
# string.split!
# 4. Sort Array into a alphabetical order
# string.sort!
# 6. Compare the list
#==> if elsle array=array
# 6.1 return of list is not the same
# 6.2 return true if list is the same
def is_anagram?(first_word, second_word)
return false if (first_word.length != second_word.length)
first=first_word.downcase.split("").sort
second=second_word.downcase.split("").sort
return true if canonical(first, second)
false
end
def canonical(first_list,second_list)
first_list==second_list
end
puts is_anagram?('iceman','iceman')
puts is_anagram?('iceman','cinema')
puts is_anagram?('pants','pants')
puts is_anagram?('CiNemA','iceman')
puts is_anagram?('acres','cares')
puts is_anagram?('cares','scare')
puts is_anagram?('iceman','acres')
puts is_anagram?('abcde2','c2abed')
puts is_anagram?('pants','turtle')
puts is_anagram?('123123','kjhasd')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment