Im stuck… the code goes were it should go but i cant see how to avoid the array to reset to 0 when the recusion takes place… can someone guide me please?
BinarySearchTree.prototype.depthFirstForEach = function (option) { // “pre-order” “post-order” “in-order(DEFAULT”
var array =
if (option === “pre-order”) { // root-left-right
array.push(this.value)
// console.log("added value: " + this.value + ")
if (this.left !== null) {
this.left.depthFirstForEach(option)
}
if (this.right !== null) {
this.right.depthFirstForEach(option)
}
return array
}
}