@mui/x-charts
Version:
The community edition of MUI X Charts components.
26 lines (25 loc) • 608 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.findMinMax = findMinMax;
/**
* Efficiently finds the minimum and maximum values in an array of numbers.
* This functions helps preventing maximum call stack errors when dealing with large datasets.
*
* @param data The array of numbers to evaluate
* @returns [min, max] as numbers
*/
function findMinMax(data) {
let min = Infinity;
let max = -Infinity;
for (const value of data ?? []) {
if (value < min) {
min = value;
}
if (value > max) {
max = value;
}
}
return [min, max];
}