keepHeightBalance(node, afterRemove) {
    let current = node;
    const traveledNodes = [];
    while (current !== null) {
      traveledNodes.push(current);
      current.height = this.getNodeHeight(current);
      if (!this.isNodeBalanced(current)) {
        const nodesToBeRestructured = afterRemove
          ? this.getNodesToRestructureAfterRemove(traveledNodes)
          : this.getNodesToRestructureAfterInsert(traveledNodes);
        this.restructure(nodesToBeRestructured);
      }
      current = current.parent;
    }
  }
Keep the height balance property by walking to
root and checking for invalid heights.