sortedIndex function

int sortedIndex(
  1. List array,
  2. dynamic value
)

Uses a binary search to determine the lowest index at which value should be inserted into array in order to maintain its sort order.

Implementation

int sortedIndex(List array, value) {
  var low = 0;
  var high = array.length;
  while (low < high) {
    var mid = (low + high) ~/ 2;
    if (array[mid] < value) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  return low;
}