freeCodeCamp Challenge Guide: Check if Tree is Binary Search Tree

Continuing the discussion from freeCodeCamp Challenge Guide: Check if Tree is Binary Search Tree:

Solution 3 (Click to Show/Hide)
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;
}


function isBinarySearchTree(tree) {
  let node = tree.root;

  let isBinary = (root) => {
    if(root === null) return true;
    if( root.left !== null && root.left.value >= root.value ) return false;
    if(root.right !== null && root.right.value < root.value) return false;

    return isBinary(root.left) && isBinary(root.right);
  }

  return isBinary(node);
}

hello and welcome back to fcc forum :slight_smile:

did you have a question or you’re sharing your solutions?

happy coding :slight_smile:

Just sharing my solution :blush: