if (substring.length === 1 && node && node.children[substring]) { // If this node is a stop node, // then the string exists. // Otherwise, the string doesn't exist. // TODO WRITE CODE HERE } // Recursive case goes here. }
// Base case goes here. var child = node.children[substring[0]]; if (child) { // This character exists in the tree. Go one layer down. // TODO WRITE CODE HERE } else { // There is no next node to go to. // String does not exist. // TODO WRITE CODE HERE } }
if (!node) { return []; } if (this.isEmpty(node.children)) { // This is a leaf node. Return the value. // Handle case if node is head. if (node.value) { return [node.value]; } else { return []; } } // TODO WRITE CODE HERE }
var strings = []; for (var char in node.children) { var child = node.children[char]; var childStrings = this.iterate(child); for (var i in childStrings) { // TODO WRITE CODE HERE } } if (node.stop) { strings.push(node.value); } return strings; }; Hint 4: iterate() recursive case