多维数组javascript的最大值

问题描述:

我有一个x列和y行的多维数组。
如何找到矩阵的最小值和最大值?
示例

I have a multidimensional array of x columns and y rows. How to find the min and the max value of the matrix? Example

[1,  37.8, 80.8, 41.8],
[2,  30.9, 69.5, 32.4],
[3,  25.4,   57, 25.7],
[4,  11.7, 18.8, 10.5],
[5,  11.9, 17.6, 10.4],
[6,   8.8, 13.6,  7.7],
[7,   7.6, 12.3,  9.6],
[8,  12.3, 29.2, 10.6],
[9,  16.9, 42.9, 14.8],
[10, 12.8, 30.9, 11.6],
[11,  5.3,  7.9,  4.7],
[12,  6.6,  8.4,  5.2],
[13,  4.8,  6.3,  3.6],
[14,  4.2,  6.2,  3.4]


var arr = [[2,3], [4,5]]; //a multidimensional array

然后得到一个数组,其中每行的最大值为

then get an array with each row's maximum with

var maxRow = arr.map(function(row){ return Math.max.apply(Math, row); });

以及

var max = Math.max.apply(null, maxRow);