Tell us what’s happening:
When I’m emulating the work of my algorithm outside of freecodecamp, it works. But it doesn’t pass the test on the website page.
Your code so far
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(){
var minValue
if (this.root == null) {
return null
}
node = this.root
minValue = node.value
while (node.left != null) {
node = node.left
minValue = node.value
}
return minValue
}
this.findMax = function(){
var maxValue
if (this.root == null) {
return null
}
node = this.root
maxValue = node.value
while (node.right != null) {
node = node.right
maxValue = node.value
}
return maxValue
}
// change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
.
Challenge: Find the Minimum and Maximum Value in a Binary Search Tree
Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/find-the-minimum-and-maximum-value-in-a-binary-search-tree