function balance(node) {
  if (node.balanceFactor > 1) {
    // left subtree is higher than right subtree
    if (node.left.balanceFactor < 0) {
      return leftRightRotation(node);
    }
    return rightRotation(node);
  } if (node.balanceFactor < -1) {
    // right subtree is higher than left subtree
    if (node.right.balanceFactor > 0) {
      return rightLeftRotation(node);
    }
    return leftRotation(node);
  }
  return node;
}
Balance tree doing rotations based on balance factor.

Depending on the `node` balance factor and child's factor
one of this rotation is performed:
- LL rotations: single left rotation
- RR rotations: single right rotation
- LR rotations: double rotation left-right
- RL rotations: double rotation right-left

@param {BinaryTreeNode} node