Skip to content

Instantly share code, notes, and snippets.

@benbuckman
Created November 30, 2012 21:07
Show Gist options
  • Select an option

  • Save benbuckman/4178619 to your computer and use it in GitHub Desktop.

Select an option

Save benbuckman/4178619 to your computer and use it in GitHub Desktop.

Revisions

  1. Ben Buckman created this gist Nov 30, 2012.
    16 changes: 16 additions & 0 deletions magicdictionary.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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'