Complete the code to check if the current character exists in the children nodes.
if (!node.children.hasOwnProperty([1])) { return false; }
The search checks if the current character char exists in the children of the current node.
Complete the code to move to the next node in the Trie for the current character.
node = node.children[[1]];node to itself.We update node to the child node corresponding to the current character char.
Fix the error in the return statement to correctly check if the word ends here.
return node.[1] === true;
isWord or end.The property isEndOfWord marks if the node represents the end of a valid word in the Trie.
Fill both blanks to complete the loop that iterates over each character in the word.
for (let [1] = 0; [2] < word.length; [1]++) { const char = word[[1]]; // rest of the code }
The loop uses i as the index variable to iterate over the word characters.
Fill all three blanks to complete the search function that returns true if the word exists in the Trie.
function search(word) {
let node = this.root;
for (let i = 0; i < word.length; i++) {
const [1] = word[i];
if (!node.children.hasOwnProperty([2])) {
return false;
}
node = node.children[[3]];
}
return node.isEndOfWord === true;
}The variable char holds the current character. We check if char exists in children and then move to that child node.