Find the Minimum and Maximum Value in a Binary Search Tree help

Find the Minimum and Maximum Value in a Binary Search Tree

Without values I cannot to test the return value. I needed to write “blindly” this code…
and somethings are wrong because fails on the test. I have no idea how can I test the code without values…

var displayTree = tree => console.log(JSON.stringify(tree, null, 2));
function Node(value) {
  this.value = value;
  this.left = null;
  this.right = null;
}
function BinarySearchTree() {
  this.root = null;
  // change code below this line
  this.findMin = function() {
    if (!(this.root)) return null;
    const node = this.root;
    while (node.left) {
      node = node.left;
    }
    return node.value;
  };

  this.findMax = function() {
    if (!(this.root)) return null;
    const node = this.value;
    while (node.right) {
      node = node.right;
    }
    return node.value;
  };
  // change code above this line
}

Thank you, I made the add method and I see what the matter.
let node = ... I declared a constant instead of variable…
And in the findMax a silly mistake: this.root and not this.value

1 Like