Solution for delete a leaf node in BST

What is your hint or solution suggestion?
Challenge: Delete a Leaf Node in a Binary Search Tree

solution
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;
  // Only change code below this line

  this.remove=(value)=>{
    if(this.root===null){return null};
    if(this.root.value==value && this.root.right===null && this.root.left===null){
      this.root=null;
      return null;
      }
    var current=this.root;
    var previous ;
    var isRight=true;
      
    function findNode(){
     
      while(current!==null && current.value!==value){
        if(value>current.value){
          previous=current;
          current=current.right;
          isRight=true;
        }
        else if(value<current.value){
          previous=current;
          current=current.left;
          isRight=false;
        }
      } 

    }
   

     findNode();
     if(current===null){
       return null;
       }
     else if(current.value===value && isRight==true){
       previous.right=null;
       return current;
     }
     else {
       previous.left=null;
       return current;
     }
  }
}
      

Link to the challenge:

Hi @hari.bodicherla !

Welcome to the forum!

I have edited your post in the correct format for guide post formatting.

Thank you, for your contribution. For future contributions, please wrap your solution within :

[details]
```
code goes here...
```
[/details]

Also, provide all of the necessary code to pass the challenge.

Also, when you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor ( </> ) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

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