const WordDictionary = function () {
this.words = {};
}
WordDictionary.prototype.addWord = function (word) {
console.log(this.words);
if (this.words[word.length]) {
this.words[word.length].push(word)
} else {
this.words[word.length] = [word]
}
};
WordDictionary.prototype.searchWord = (word) => {
if (!this.words[word.length]) {
return false;
}
if (!word.includes('.')) {
return this.words[word.length].includes(word);
}
const reg = new RegExp(word);
return this.words[word.length].some((i) => {
return reg.test(i);
})
}
WordDictionary.prototype.addWord('6783');
console.log(WordDictionary.prototype.words)
console