Skip to content

Instantly share code, notes, and snippets.

@ybur-yug
Last active December 21, 2015 23:18
Show Gist options
  • Save ybur-yug/6380893 to your computer and use it in GitHub Desktop.
Save ybur-yug/6380893 to your computer and use it in GitHub Desktop.
Anagram detector. returns true if input word is an anagram of anything in the input array possible_anagrams.
def anagrams(word, possible_anagrams)
individual_letters = []
anagrams = []
possible_anagrams.each do |anagram|
individual_letters.push((anagram.split("")))
end
individual_letters.each do |anagram|
anagram.sort!
end
individual_letters.each do |words|
if word.split('').sort.join('') == words.join('')
puts true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment