src/common-ancestor.js
function findAncestorDistance(src, target, currentDistance) {
  if (target === src) {
    return currentDistance;
  }

  const distances = [];
  src.getParents().forEach((srcParentChunkGroup) => {
    const distance = findAncestorDistance(
      srcParentChunkGroup,
      target,
      currentDistance + 1
    );
    if (distance >= 0) {
      distances.push(distance);
    }
  });
  if (distances.length === 0) {
    return -1;
  }
  return Math.min(...distances);
}
function findAncestorDistance(src, target, currentDistance) {
  if (target === src) {
    return currentDistance;
  }

  const distances = [];
  src.getParents().forEach((srcParentChunkGroup) => {
    const distance = findAncestorDistance(
      srcParentChunkGroup,
      target,
      currentDistance + 1
    );
    if (distance >= 0) {
      distances.push(distance);
    }
  });
  if (distances.length === 0) {
    return -1;
  }
  return Math.min(...distances);
}
Find an ancestor of a chunk. Return the distance from the target or -1 if not found.

@param {string} src
@param {string} target
@param {number} currentDistance
@return {number} distance from target of parent or -1 when not found