var max = 0,
result = 0
for(var i=0i<array.lengthi++){
result += array[i]
if(array[i] >max){
max = array[i]
}
}
就是一般的方法
还是很简答的//最小值
Array.prototype.min = function() {
var min = this[0]
var len = this.length
for (var i = 1i <leni++){
if (this[i] <min){
min = this[i]
}
}
return min
}
//最大值
Array.prototype.max = function() {
var max = this[0]
var len = this.length
for (var i = 1i <leni++){
if (this[i] >max) {
max = this[i]
}
}
return max
}
希望对你有帮助