15.8.2.11 Math.max([value1[, value2[, ... ]]])

2010-07-12

number Math.max([value1number|mixed[, value2:number|mixed[, ... ]]])

Returns the highest number of all given arguments (all coerced to number). Any NaN causes a return of NaN. Uses RelationalComparison (11.8.5), except that +0 is greater than -0.

Code: (Meta Ecma)
Math.max = function(){
if (arguments.length == 0) return -Infinity;
var arr = [];
for (var i=0, n=arguments.length; i var largestV = arr[0];
for (i=1; i if (isNaN(arr[i ])) return NaN;
if (RelationalComparison(arr[i ],largestV) || (arr[i ] === +0 && largestValue === -0)) largestV = arr[i ];
}
return largestV;
}