/*平均值:*/ [1,2,3,4,5,6,7,8,9,10].reduce((a,b,c)=>(a*c+b)/(c+1))
/*最大值:*/ [1,2,3,4,5,6,7,8,9,10].reduce((a,b)=>(a>b?a:b))
/*最小值 */ [1,2,3,4,5,6,7,8,9,10].reduce((a,b)=>(a<b?a:b))
/*求和 */ [1,2,3,4,5,6,7,8,9,10].reduce((a,b)=>a+b)
注意:Array的reduce方法需要es5支持,如果浏览器不支持可以使用以下shim
if (typeof Array.prototype.reduce != "function") { Array.prototype.reduce = function (callback, initialValue ) { var previous = initialValue, k = 0, length = this.length; if (typeof initialValue === "undefined") { previous = this[0]; k = 1; } if (typeof callback === "function") { for (k; k < length; k++) { this.hasOwnProperty(k) && (previous = callback(previous, this[k], k, this)); } } return previous; }; }