8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5eb1195 commit 392cd98Copy full SHA for 392cd98
src/data-structures/trie/Trie.js
@@ -43,7 +43,9 @@ export default class Trie {
43
* @return {boolean}
44
*/
45
doesWordExist(word) {
46
- return !!this.getLastCharacterNode(word);
+ const lastCharacter = this.getLastCharacterNode(word);
47
+
48
+ return !!lastCharacter && lastCharacter.isCompleteWord;
49
}
50
51
/**
src/data-structures/trie/__test__/Trie.test.js
@@ -45,7 +45,8 @@ describe('Trie', () => {
trie.addWord('caption');
expect(trie.doesWordExist('cat')).toBe(true);
- expect(trie.doesWordExist('cap')).toBe(true);
+ expect(trie.doesWordExist('cats')).toBe(true);
+ expect(trie.doesWordExist('cap')).toBe(false);
expect(trie.doesWordExist('call')).toBe(false);
});
52
0 commit comments