sortByNumericArray method
List<T>
sortByNumericArray(
- TFuncMapper<
T, List< funcGetNumericArray, [num> > - bool isDescending = false
Implementation
List<T> sortByNumericArray(TFuncMapper<T, List<num>> funcGetNumericArray, [ bool isDescending = false ]) {
List<T> lst = this.toList(growable: true);
lst.sort((T a, T b) {
List<num> arrV1 = funcGetNumericArray(a);
List<num> arrV2 = funcGetNumericArray(b);
if (arrV1.length != arrV2.length) {
throw "arrV1.length [${arrV1.length}] is different from arrV2.length [${arrV2.length}]";
}
for (int i = 0; i < arrV1.length; i++) {
num v1 = arrV1[i];
num v2 = arrV2[i];
if (isDescending) {
v1 *= -1;
v2 *= -1;
}
if (v1 < v2) return -1;
if (v1 > v2) return 1;
}
return 0;
});
return lst;
}