containsAll method
Whether this list contains all elements in other
.
It's time-complexity is O(n²) if other
's contains function is O(n).
[1, 2, 3].containsAll([1, 2]); // true
[1, 2].containsAll([1, 2, 3]); // false
[1, 2, 1].containsAll([1, 2]); // true
[1, 2].containsAll([1, 2, 1]); // true
[1].containsAll([]); // true
[].containsAll([]); // true
Implementation
@useResult bool containsAll(Iterable<Object?> other) {
for (final element in other) {
if (!contains(element)) {
return false;
}
}
return true;
}