I have a multidimensional array of x columns and y rows. How can I find the min and the max value of the matrix? Example:
[[1, 37.8, 80.8, 41.8],
[2, 30.9, 69.
You can also achieve this with a reduction (it's slower but if the array is not huge, it doesn't matter) resulting in a object containing both the min and the max like so:
matrix.reduce(function (res, item) {
item.forEach(function (val) {
if (!res.hasOwnProperty('max') || val > res.max) res.max = val;
if (!res.hasOwnProperty('min') || val < res.min) res.min = val;
});
return res;
}, {});