in the JS version of the Inver Binary Tree problem, it's written that you should get a binary tree in the form of an object, but they give it to you as an array. Is it normal ?
Basically, just like @stellari said, "you are not supposed to create your own data structure".
your newTree should be defined as:
var newTree=new TreeNode(root.val); newTree.left = invertTree(root.right); newTree.right = invertTree(root.left);
Besides, lots of people use swap, which avoids new "instances of the predefined TreeNode type".
var temp = root.left; root.left = root.right; root.right = temp; invertTree(root.left); invertTree(root.right); return root;