Complete the code to initialize a TrieNode with an empty children object.
class TrieNode { constructor() { this.children = [1]; this.isEndOfWord = false; } }
The children property should be an empty object {} to store child nodes by character keys.
Complete the code to mark the node as the end of a word.
class TrieNode { constructor() { this.children = {}; this.isEndOfWord = [1]; } }
When initializing, isEndOfWord should be false because the node does not represent the end of a word yet.
Fix the error in the constructor to properly initialize children as an empty object.
class TrieNode { constructor() { this.children = new [1](); this.isEndOfWord = false; } }
Using new Object() correctly initializes an empty object for children.
Fill both blanks to complete the method that adds a child node for a character.
addChild(char) {
if (!this.children.hasOwnProperty([1])) {
this.children[[2]] = new TrieNode();
}
}The character variable char is used as the key to check and add a child node.
Fill all three blanks to complete the method that checks if a child node exists for a character.
hasChild([1]) { return this.children.hasOwnProperty([2]) && this.children[[3]] !== undefined; }
The method uses the parameter char to check if the child exists in the children object.