Split into `firstInversion = issorted` and `isSorted = (compare, a, i, j) => firstInversion(compare, a, i, j) === j`.