mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 07:01:18 +08:00
Fix method Trie::doesWordExist() (#175)
Method Trie::doesWordExist() return `true` when word is complete otherwise `false`
This commit is contained in:
parent
5eb1195c61
commit
392cd9806d
@ -43,7 +43,9 @@ export default class Trie {
|
||||
* @return {boolean}
|
||||
*/
|
||||
doesWordExist(word) {
|
||||
return !!this.getLastCharacterNode(word);
|
||||
const lastCharacter = this.getLastCharacterNode(word);
|
||||
|
||||
return !!lastCharacter && lastCharacter.isCompleteWord;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user