hasTheSameElements<T> method
Return true if all items in this are also in other
This is different to ListEquality in the
collection package
as this function does not require the list elements to be in the
same order.
Implementation
bool hasTheSameElements<T>(Iterable<T> other) {
if (isEmpty && other.isEmpty) {
return true;
}
if (length != other.length) {
return false;
}
var checklist = List<bool>.filled(other.length, false, growable: false);
for (int 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;
}