function setCoordAvg(xOrY, onPts, offPts, group) {
  const ptIndex = xOrY === 'x' ? 0:1;
  // Average of the coordinates to align
  const avg = group.map(expanded => {
    const index = expanded.index;
    return (expanded.on? onPts:offPts)[index][ptIndex];
  }).reduce((a, b) => a + b)/group.length;
  // Set the coordinates
  group.forEach(expanded => {
    const index = expanded.index;
    (expanded.on? onPts:offPts)[index][ptIndex] = avg;
  });
}
Average of the points to be aligned by x or y axis.
@param { 'x'|'y' } xOrY Average of x coordinate or y coordinate
@param { [number, number][] } onPts 
@param { [number, number][] } offPts 
@param { {on: boolean, index: number}[] } group Alignment information