Data Structures - Check if Tree is Binary Search Tree


At this moment, to debug an recursion problem… I still use console.log( )to see the true/false return.
It this good practice or common practice ? It took quite a long time for me. Wish to know if there is other convenient way. Thanks :smiley:

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;
function isBinarySearchTree(tree) {
  // Only change code below this line

  console.log(`####### Begin binary search Tree #######`)
  function isSubTreeBinary(node){
    if(! node){
      return true
    if(node.left && node.left.value >= node.value){
      return false
    if(node.right && node.right.value <= node.value){
      return false
    let x = (
      isSubTreeBinary(node.left) &&
    return x

  return isSubTreeBinary(tree.root)

  // Only change code above this line

Challenge: Data Structures - Check if Tree is Binary Search Tree

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.