function getAncestor(node, node1, node2) {
  let matchingNode = null;
  let isAncestor = false;

  if(!node) {
    return {matchingNode, isAncestor};
  }

  const left = getAncestor(node.left, node1, node2);
  if (left.isAncestor) {
    return left;
  }

  const right = getAncestor(node.right, node1, node2);
  if (right.isAncestor) {
    return right;
  }

  if(node === node1 && node2 === node1) {

    // already found both nodes since they are the same
    matchingNode = node;
    isAncestor = true;

  } else if(left.matchingNode && right.matchingNode ||
    left.matchingNode === node1 && node === node2 || left.matchingNode === node2 && node === node1 ||
    right.matchingNode === node1 && node === node2 || right.matchingNode === node2 && node === node1) {

    // if we found both nodes already then we found an ancestor
    matchingNode = node;
    isAncestor = true;

  } else if(node === node1 || node === node2) {

    // set match
    matchingNode = node;

  } else {

    // bubble up partial match
    return left.matchingNode ? left : right;

  }

  return {matchingNode, isAncestor};
}
@param node
@param node1
@param node2
@returns {matchingNode: Node, isAncestor: boolean} Node matches either Node1, Node2 or common ancestor (if flag is true).