Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2012 21:07
What would you like to do?
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
console.log findAllWords 'okhellokittynofarm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment