Skip to content

Instantly share code, notes, and snippets.

@raul-gracia
Last active August 29, 2015 13:57
Show Gist options
  • Save raul-gracia/9694196 to your computer and use it in GitHub Desktop.
Save raul-gracia/9694196 to your computer and use it in GitHub Desktop.
Kata: Arrh, grabscrab!

Kata: Arrh, grabscrab!

Pirates have notorious difficulty with enunciating. They tend to blur all the letters together and scream at people.

At long last, we need a way to unscramble what these pirates are saying.

Write a function that will accept a jumble of letters as well as a dictionary, and output a list of words that the pirate might have meant.

For example:

grabscrab "ortsp", ["sport", "parrot", "ports", "matey"]

Should return:

["sport", "ports"]

Return an empty array if there are no matches.

def grabscrab anagram, dictionary
# your code goes here
end
Test.expect(grabscrab("trisf", ["first"]) == ["first"], "Should have found 'first'")
Test.expect(grabscrab("oob", ["bob", "baobab"]) == [], "Should not have found anything")
Test.expect(grabscrab("ainstuomn", ["mountains", "hills", "mesa"]) == ["mountains"], "Should have found 'mountains'")
Test.expect(grabscrab("oolp", ["donkey", "pool", "horse", "loop"]) == ["pool", "loop"], "Should have found 'pool' and 'loop'")
Test.expect(grabscrab("ortsp", ["sport", "parrot", "ports", "matey"]) == ["sport", "ports"], "Should have found 'sport' and 'ports'")
Test.expect(grabscrab("ourf", ["one","two","three"]) == [], "Should not have found anything")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment