Checking Symmetric Tree
Symmetric Tree:
Each node's left and right children can be swapped without changing the tree's look.
Symmetry Analysis:
We dive into recursive logic with isMirror, comparing subtrees to check symmetry by comparing node values and their children.
Symmetry Check:
Using isSymmetric, we oversee the whole tree's symmetry by calling isMirror on left and right subtrees.
1class Node {
2    constructor(val) {
3      this.val = val;
4      this.left = null;
5      this.right = null;
6    }
7  }
8
9  
10  const one = new Node(1);
11  const two = new Node(2);
12  const three = new Node(3);
13  const threeRight = new Node(3);
14  const twoRight = new Node(2);
15  const four = new Node(4);
16  const fourRight = new Node(4);
17  const five = new Node(5);
18  const six = new Node(6);
19  const seven = new Node(7);
20  const eight = new Node(8);
21
22  
23//   one.left = two;
24//   one.right = three;
25//   two.right = five;
26//   two.left = four;
27//   five.right = seven;
28//   five.left = six;
29//   seven.left = eight;
30
31
32  one.left = two;
33  one.right = twoRight;
34  two.right = four;
35  two.left = three;
36  twoRight.right = threeRight;
37  twoRight.left = fourRight;
38 
39  function isMirror(node1, node2) {
40    if(!node1 && !node2) return true;
41    if(!node1 || !node2) return false;
42    if(node1.val !== node2.val) return false;
43    
44    return isMirror(node1.left, node2.right) && isMirror(node1.right, node2.left)
45  }
46  var isSymmetric = function(root) {
47    if(!root) return true;
48    return isMirror(root.left, root.right)
49  };
50
51  
52console.log(isSymmetric(one))
53