Created
January 4, 2014 08:13
-
-
Save jkeesh/8252967 to your computer and use it in GitHub Desktop.
proof of concept lexicon
This file contains hidden or 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
function Lexicon(file){ | |
this.data = { | |
'a': { | |
'b': { | |
's': {} | |
} | |
} | |
}; | |
} | |
Lexicon.prototype.contains = function(word){ | |
console.log("Contains: " + word + "?"); | |
var curDict = this.data; | |
for(var i = 0; i < word.length; i++){ | |
var curLetter = word.charAt(i); | |
if(curLetter in curDict){ | |
curDict = curDict[curLetter] | |
}else{ | |
return false; | |
} | |
} | |
return true; | |
} | |
var a = new Lexicon(); | |
console.log(a.contains("abs")); | |
console.log(a.contains("abx")); | |
console.log(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment