isSubList<T> method

bool isSubList<T>(
  1. Iterable<T> other
)

Return true if this is a sublist of other.

Does not care if the lists are in the same order.

Implementation

bool isSubList<T>(Iterable<T> other) {
  if (length > other.length) {
    return false;
  }

  var checklist = List<bool>.filled(other.length, false, growable: false);

  for (var i = 0; i < length; i++) {
    var found = false;
    for (var j = 0; j < other.length; j++) {
      if (checklist[j]) continue;

      if (elementAt(i) == other.elementAt(j)) {
        checklist[j] = true;
        found = true;
        break;
      }
    }
    if (!found) return false;
  }
  return true;
}