获取数组中最大值的方法(最小值同理)
1、
var tmp = [1,3,5,3,7,10,9,-111];
biggest = Math.max.apply(null,tmp); //根源是?
alert(biggest); //10 success!
但如果数组中出现undefined则会失败。出现null不会失败
2、
var tmp = [1,3,5,3,null,10,9,-111];
var biggest; //= tmp.toString().split(",").sort().pop();
for(var i=0; i<tmp.length; i++){
var thisNum = tmp[i] ? tmp[i] : Number.MIN_VALUE;
biggest = biggest - thisNum > 0 ? biggest : thisNum;
} //成功
3、尝试先sort()排序再pop()输出最大值,失败!