The following code
var interval = function (a, b) {
var i, list = [];
for (i = a; i <= b; i++) {
list.push(i);
}
return list;
},
xs = interval(1, 500000);
Math.max.apply(null, xs);
generates an Uncaught RangeError: Maximum call stack size exceeded. How to overcome?
Note that the interval function is just a quick way to generate test data.
I used the Math.max.apply method because it is described here: Mozilla developer network
This is not an acceptable solution because javascript has a maximum number of arguments allowed for a function call, thanks to Rocket Hazmat for pointing it out, see his answer for more informations.
The underscore.js library uses a simple implementation for the max function, and I believe that the most appropriate solution is to include a simple max implementation in the codebase and use it. See @AnotherDev answer for more details