Magic Dictionary algo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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