Skip to content

Instantly share code, notes, and snippets.

@mosdevly
Created November 17, 2014 00:07
Show Gist options
  • Save mosdevly/b2c118fd008158356565 to your computer and use it in GitHub Desktop.
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.
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