getMaxInRange method
Finds the maximum value of the numbers in array
in the range from
firstIx
to lastIx
, both indices inclusive.
Both indices may have the values null (at the same time), the the entire
array
is searched.
array
may contain null values, they are skipped.
Returns the maximum, if 2 maxima with the same value exist,
the 1st one is returned.
Implementation
static double getMaxInRange(Float64List arr, int firstIx, int lastIx) {
double max_value = -double.maxFinite;
if (arr == null) return max_value;
double curval;
if (firstIx == null && lastIx == null) {
firstIx = 0;
lastIx = arr.length - 1;
}
int n = lastIx - firstIx + 1;
if (n < 0) {
int temp = lastIx;
lastIx = firstIx;
firstIx = temp;
}
if (lastIx > arr.length - 1) lastIx = arr.length - 1; // security check
for (int i = firstIx; i <= lastIx; i += 1) {
curval = arr[i];
if (curval != null && curval > max_value) {
max_value = curval;
}
}
return max_value;
}