Source: https://bigfrontend.dev/problem/invert-a-binary-tree
https://leetcode.com/problems/invert-binary-tree/

// Edge cases if node is null return null
// If one node without any children, nothing to swap
// If one node exists, swap children and then recursively swap left/right children trees
// O(N) time where N is number of nodes in tree, space is O(N) where the height could be at most the number of nodes
function invert(node) {
// Base Cases:
// If no node, return null
if (!node) {
return null;
}
const tempNode = node.left;
node.left = node.right;
node.right = tempNode;
// If node with children, swap left/right and then recursively invert left/right subtree
invert(node.left);
invert(node.right);
return node;
}