Skip to content

Instantly share code, notes, and snippets.

@benbuckman
Created November 30, 2012 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbuckman/4178619 to your computer and use it in GitHub Desktop.
Save benbuckman/4178619 to your computer and use it in GitHub Desktop.
Magic Dictionary algo
dict = ['hello', 'kitty', 'farm']
isWordInDict = (word)->
(dict.indexOf(word) > -1)
findAllWords = (str)->
words = []
for startInd in [0..(str.length - 1)]
for endInd in [(startInd + 1)..str.length]
word = str.substr startInd, endInd - startInd
if isWordInDict word then words.push word
words
console.log findAllWords 'okhellokittynofarm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment