Add Trie.

This commit is contained in:
Oleksii Trekhleb 2018-03-30 20:45:51 +03:00
parent b7675f8834
commit 6e4d7a1750
2 changed files with 4 additions and 4 deletions

View File

@ -26,7 +26,7 @@ export default class Trie {
return lastCharacter.suggestChildren(); return lastCharacter.suggestChildren();
} }
doesWordExists(word) { doesWordExist(word) {
return !!this.getLastCharacterNode(word); return !!this.getLastCharacterNode(word);
} }

View File

@ -44,8 +44,8 @@ describe('Trie', () => {
trie.addWord('car'); trie.addWord('car');
trie.addWord('caption'); trie.addWord('caption');
expect(trie.doesWordExists('cat')).toBeTruthy(); expect(trie.doesWordExist('cat')).toBeTruthy();
expect(trie.doesWordExists('cap')).toBeTruthy(); expect(trie.doesWordExist('cap')).toBeTruthy();
expect(trie.doesWordExists('call')).toBeFalsy(); expect(trie.doesWordExist('call')).toBeFalsy();
}); });
}); });