windowResort = (elements, rankCompare, fullCompare) => {
  assertRankSorted(elements, rankCompare);
  const { length } = elements;
  let i = 0;
  let optInnerIterator;
  return harden({
    [Symbol.iterator]: () =>
      harden({
        next: () => {
          if (optInnerIterator) {
            const result = optInnerIterator.next();
            if (result.done) {
              optInnerIterator = undefined;
              // fall through
            } else {
              return result;
            }
          }
          if (i < length) {
            const value = elements[i];
            let j = i + 1;
            while (j < length && rankCompare(value, elements[j]) === 0) {
              j += 1;
            }
            if (j === i + 1) {
              i = j;
              return harden({ done: false, value });
            }
            const similarRun = elements.slice(i, j);
            i = j;
            const resorted = sortByRank(similarRun, fullCompare);
            // Providing the same `fullCompare` should cause a memo hit
            // within `assertNoDuplicates` enabling it to avoid a
            // redundant resorting.
            assertNoDuplicates(resorted, fullCompare);
            // This is the raw JS array iterator whose `.next()` method
            // does not harden the IteratorResult, in violation of our
            // conventions. Fixing this is expensive and I'm confident the
            // unfrozen value does not escape this file, so I'm leaving this
            // as is.
            optInnerIterator = resorted[Symbol.iterator]();
            return optInnerIterator.next();
          } else {
            return harden({ done: true, value: null });
          }
        },
      }),
  });
}
Asserts that `elements` is already rank sorted by `rankCompare`, where there
may be contiguous regions of elements tied for the same rank.
Returns an iterable that will enumerate all the elements in order
according to `fullOrder`, which should differ from `rankOrder` only
by being more precise.

This should be equivalent to resorting the entire `elements` array according
 to `fullOrder`. However, it optimizes for the case where these contiguous
runs that need to be resorted are either absent or small.

@template {Passable} T
@param {T[]} elements
@param {RankCompare} rankCompare
@param {FullCompare} fullCompare
@returns {Iterable<T>}