1
var Trie = function () {10
Trie.prototype.insert = function (word) {16
let tail = word.substring(1);18
if (!this.children[head]) {19
this.children[head] = new Trie();21
this.children[head].insert(tail);25
* @param {string} word28
Trie.prototype._search = function (word, method) {30
if (method === "search") {37
let tail = word.substring(1);39
if (!this.children[head]) {43
return this.children[head][method](tail);47
* @param {string} word50
Trie.prototype.search = function (word) {51
return this._search(word, "search");55
* @param {string} prefix58
Trie.prototype.startsWith = function (prefix) {59
return this._search(prefix, "startsWith");63
* Your Trie object will be instantiated and called as such:64
* var obj = new Trie()66
* var param_2 = obj.search(word)67
* var param_3 = obj.startsWith(prefix)