insertInOrder<T> function

List<T> insertInOrder<T>(
  1. T n,
  2. Iterable<T> it
)

Insert an element before the first greater element

Implementation

List<T> insertInOrder<T>(T n, Iterable<T> it) {
  List<T> l = List.from(it);
  List<T> result = List.from(l);
  for (int i = 0; i < l.length; i++) {
    if ((l[i] as num) >= (n as num)) {
      result.insert(i, n);
      return result;
    }
  }
  result = result + [n];
  return result;
}