Finding max or min in Array in Javascript

javascript, es5

You can't pass an array to Math.max in Javascript. Here's how to deal with that in ES5.

You can't pass an array directly to Math.max in Javascript - instead do:

Math.max.apply( null, [ 1, 2, 3, 4 ] );

This doesn't extend to multi-dimensional arrays though. For a two dimensional array I use:

//find numeric max in a two dimensional array
var runningMax = 0, i, i2;
for(i = 0, i2 = arr.length; i<i2; i++) {
  runningMax = Math.max.apply(null, arr[i].concat(runningMax));