Here is the input code:
var newTree = {};
newTree.value = value;
newTree.children = [] // fix me
Object.assign(newTree, treeMethods)
return newTree;
};
var treeMethods = {};
treeMethods.addChild = function(value) {
const newNode = Tree(value);
this.children.push(newNode)
};
treeMethods.contains = function(target) {
let currentTree = this.children
while (currentTree != null) {
if (currentTree.indexOf(target) > -1) return true
currentTree = this.children[target]
}
return false
};
I am trying to determine if, given a target value via the contains function, can I find the target value called to contains() in parent nodes or descendant nodes.
Please don't give me the full answer but if you could push me in the right direction.