Last active
December 21, 2015 23:18
-
-
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.
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 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