Complete the code to add a character node to the children map.
if (!node.children.has(char)) { node.children.[1](char, new TrieNode()); }
The Map object uses the set method to add a key-value pair. Here, we add a new character node.
Complete the code to move to the next node for the current character.
node = node.children.[1](char)!;The get method retrieves the value for a given key in a Map. Here, it gets the child node for the character.
Fix the error in marking the end of a word in the Trie node.
node.[1] = true;The property isEnd is commonly used to mark the end of a word in a Trie node.
Fill both blanks to complete the loop that inserts each character of the word.
for (const [1] of word) { if (!node.children.[2]([1])) { node.children.set([1], new TrieNode()); } node = node.children.get([1])!; }
The loop variable is commonly named char to represent each character. The has method checks if the character node exists in the children map.
Fill all three blanks to complete the insert method for the Trie.
insert(word: string): void {
let node = this.root;
for (const [1] of word) {
if (!node.children.[2]([1])) {
node.children.set([1], new TrieNode());
}
node = node.children.get([1])!;
}
node.[3] = true;
}The loop variable is char. The has method checks for the character in children. The isEnd property marks the end of the word.