Created
November 17, 2014 00:07
-
-
Save mosdevly/b2c118fd008158356565 to your computer and use it in GitHub Desktop.
Write a method that takes two inputs: a single word and a dictionary of other words. The method should output all the words in the dictionary which our single word can scrabble to. For example, cat is an anagram of act.
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 word_unscrambler(str, words) | |
idx = 0 | |
matches = [] | |
while idx < words.length | |
sorted = words[idx].chars.sort.join | |
match = str.chars.sort.join | |
word = words[idx] | |
if sorted == match | |
matches << word | |
end | |
idx += 1 | |
end | |
matches | |
end | |
# word_unscrambler("cat", ["tic", "toc", "tac", "toe", "act"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment