I used his technique for a while but then I had to find the max and min of an array of 1 million values which is more than the maximum number of arguments to a function in most javascript implementation so I rewrote it a such:
Array.prototype.min = function() {
var increment = 50000;
if(this.length > increment){
var reduced_array = [];
for(var i=0;i<this.length;i+=increment) {
reduced_array.push(Math.min.apply(Math,
this.slice(i,i+increment-1)));
} }else {
return Math.min.apply(Math, this);
}
return reduced_array.min();
};
Array.prototype.max = function(array) { var increment = 50000;
if(this.length > increment){
var reduced_array = [];
for(var i=0;i<this.length;i+=increment) {
reduced_array.push(Math.max.apply(Math, this.slice(i,i+increment-1)));
}
}else {
return Math.max.apply(Math, this);
}
I'm sure someone can suggest a better way.