mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Add Trie.
This commit is contained in:
parent
b7675f8834
commit
6e4d7a1750
@ -26,7 +26,7 @@ export default class Trie {
|
||||
return lastCharacter.suggestChildren();
|
||||
}
|
||||
|
||||
doesWordExists(word) {
|
||||
doesWordExist(word) {
|
||||
return !!this.getLastCharacterNode(word);
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,8 @@ describe('Trie', () => {
|
||||
trie.addWord('car');
|
||||
trie.addWord('caption');
|
||||
|
||||
expect(trie.doesWordExists('cat')).toBeTruthy();
|
||||
expect(trie.doesWordExists('cap')).toBeTruthy();
|
||||
expect(trie.doesWordExists('call')).toBeFalsy();
|
||||
expect(trie.doesWordExist('cat')).toBeTruthy();
|
||||
expect(trie.doesWordExist('cap')).toBeTruthy();
|
||||
expect(trie.doesWordExist('call')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user