Solution suggestion for Depth First Search in Binary Tree

What is your solution suggestion?

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.inorder = function(){
    if(this.root === null){
      return null;
    }
    let nodes = [];
    function leftDataRight(root){
      if (root.left){
        leftDataRight(root.left)
        }
      nodes.push(root.value);
      if (root.right) {
        leftDataRight(root.right);
        }
    }
    leftDataRight(this.root);
    return nodes;
  }
  this.preorder = function(){
    if(this.root === null){
      return null;
    }
    let nodes = [];
    function dataLeftRight(root){
      nodes.push(root.value);
      if (root.left){
        dataLeftRight(root.left)
        }
      if (root.right) {
        dataLeftRight(root.right);
        }
    }
    dataLeftRight(this.root);
    return nodes;
  }
  this.postorder = function(){
    if(this.root === null){
      return null;
    }
    let nodes = [];
    function leftRightData(root){
      if (root.left){
        leftRightData(root.left)
        }
      if (root.right) {
        leftRightData(root.right);
        }
      nodes.push(root.value);
    }
    leftRightData(this.root);
    return nodes;
  }
  
  // Only change code above this line
}

Challenge: Use Depth First Search in a Binary Search Tree

Link to the challenge:

Hello there.

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 (’).

1 Like

Thank you for your guide post contribution. I have taken your suggestions and included them in the guide post.

We look forward to your further contribution.