Creates a new Trie
instance.
Optional
initialWords: string[] | readonly string[]Optional array of words to initialize the trie with.
Makes the Trie
iterable.
Words are yielded in their insertion order by default.
Optional
reversed: boolean = falseOptional boolean
to reverse iteration order.
An iterator for the trie's entries.
Adds a word to the trie. If the word already exists, it will not create duplicates and the original insertion order is preserved.
The word to add.
Removes a word from the trie.
The word to remove.
true
if the word was found and removed, false
if not found.
Returns an iterator of all words in the trie.
Words are yielded in their insertion order by default.
Optional
reversed: boolean = falseOptional boolean
to reverse iteration order.
An iterator of the trie's entries.
Finds all words that start with the given prefix.
The prefix to search for.
An array of matching words.
Checks if a word exists in the trie.
The word to check.
true
if the exact word exists, false
otherwise.
A standard trie (prefix tree) implementation that extends
AbstractTrie
.Example