sortByNumber<T> static method
Sorts the given list by the given parameter by
.
Default sorting order is ascending. This can be changed by setting the descending
to true.
Implementation
static void sortByNumber<T>({
required List<T> items,
required num Function(T a) by,
bool descending = false,
}) {
for (int i = 0; i < items.length; i++) {
for (int j = i; j < items.length; j++) {
if (descending) {
if (by(items[i]) < by(items[j])) {
dynamic currentValue = items[j];
items[j] = items[i];
items[i] = currentValue;
}
} else {
if (by(items[i]) > by(items[j])) {
dynamic currentValue = items[j];
items[j] = items[i];
items[i] = currentValue;
}
}
}
}
}