min max values 2D array javascript

Liz

I've found lots of similar posts, but none yet that fully satisfy the question: How can I get the min & max values from the following 2D array in javascript?

[[1,2,3],[4,5,6],[7,8,9]]

i.e., return 1 and 9.

this question isn't quite what I'm after (as the user wants to ignore col 0), and here asks only for a 1D array.

The accepted answer here asks only for the first value of each set.

Can anyone point me to the correct (accepted) method? Many thanks!

Andy

How about flattening the array, then using Math.max.apply and Math.min.apply:

var arr = [[1,2,3],[4,5,6],[7,8,9]].reduce(function (p, c) {
  return p.concat(c);
});

var max = Math.max.apply(null, arr); // 9
var min = Math.min.apply(null, arr); // 1

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用 javascript 的 Min Max 验证

来自分类Dev

icCube - InterpolateRGBColors based on min & max values?

来自分类Dev

Numpy计算随机2D或1D数组中的Min Max

来自分类Dev

Javascript Array Map 2D数组

来自分类Dev

Javascript Array Map 2D数组

来自分类Dev

Java 2D数组矩阵在行中找到MAX,在列中找到MIN

来自分类Dev

在2D阵列中的行中找到MAX,在列中找到MIN

来自分类Dev

如何使用Array.from使用MIN MAX生成范围

来自分类Dev

Disabling HTML button with JavaScript when text reaches min/max size

来自分类Dev

如何在JavaScript中同时检查Min和Max值?

来自分类Dev

2D Array Platformer Wall Collision - Javascript

来自分类Dev

从MIN到MAX排序

来自分类Dev

iOS Swift max(),min()

来自分类Dev

MIN MAX查询

来自分类Dev

Python max()与min()

来自分类Dev

Excel formula - min, max

来自分类Dev

Java Min Max方法

来自分类Dev

max() 和 min() 蟒蛇

来自分类Dev

优化 MIN & MAX 查询

来自分类Dev

VLOOKUP 结合 MIN 或 MAX

来自分类Dev

JavaScript中BigInt类型的Math.max和Math.min的替代

来自分类Dev

creating a <br> line after 30 variable's in an 2d array javascript

来自分类Dev

MYSQL的MAX MIN日期范围

来自分类Dev

文字排序顺序的MIN / MAX

来自分类Dev

MIN和MAX的MySQL索引

来自分类Dev

Python Min Max While循环

来自分类Dev

文字排序顺序的MIN / MAX

来自分类Dev

SQL MIN(),MAX()和AVG

来自分类Dev

Max-Min 和 Min-Min 算法实现