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.
Most answers here use apply
or the spread operator ...
to call the Math.max
function with all the elements of an array as parameters.
For large arrays it is safer to use reduce:
// returns maximum of an array
const getArrayMax = array => array.reduce((a, b) => Math.max(a, b));
// returns maximum of a 2D array
const getArrayMax2d = array2d => getArrayMax(array2d.map(getArrayMax));