code: function select(ids, coords, k, left, right, axis) {
  
      while (right > left) {
          if (right - left > 600) {
              const n = right - left + 1;
              const m = k - left + 1;
              const z = Math.log(n);
              const s = 0.5 * Math.exp(2 * z / 3);
              const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
              const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
              const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
              select(ids, coords, k, newLeft, newRight, axis);
          }
  
          const t = coords[2 * k + axis];
          let i = left;
          let j = right;
  
          swapItem(ids, coords, left, k);
          if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
  
          while (i < j) {
              swapItem(ids, coords, i, j);
              i++;
              j--;
              while (coords[2 * i + axis] < t) i++;
              while (coords[2 * j + axis] > t) j--;
          }
  
          if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);
          else {
              j++;
              swapItem(ids, coords, j, right);
          }
  
          if (j <= k) left = j + 1;
          if (k <= j) right = j - 1;
      }
  }
docs: custom Floyd-Rivest selection algorithm: sort ids and coords so that [left..k-1] items are smaller than k-th item (on either x or y axis)