function invertTree(head) {
if (head) {
var temp = head.left;
head.left = head.right;
head.right = temp;
invertTree(head.left);
invertTree(head.right);
}
return head;
}
function invertTree(node) {
if(!node) return;
[node.left, node.right] = [node.right, node.left];
invertTree(node.left);
invertTree(node.right);
return node;
}
// invert binary tree using recursive function
function invertTree(node) {
if (node && node.left) {
let left = node.left;
node.left = node.right;
node.right = left;
invertTree(node.right);
invertTree(node.left);
}
return node;
}