Here you can find the source of mean()
Array.prototype.mean = function() { return !this.length ? 0 : this.reduce(function(pre, cur, i) { return (pre * i + cur) / (i + 1); });/*from w w w . j a v a2 s . c o m*/ } console.log( [1,2,3,4,5].mean() ); // 3 console.log( [].mean() ); // 0
Array.prototype.mean = function () { var sum = this.reduce( function (prev, cur) { return prev + cur; ); return sum / this.length;
Array.prototype.mean = function(){ return this.reduce(function(previousMean, currentValue, i){ return previousMean + (1/(i + 1))*(currentValue - previousMean); }); }; Array.prototype.median = function() { var values = this; values.sort( function(a,b) {return a - b;} ); var half = Math.floor(values.length/2); ...
Array.prototype.mean = function () { var sum = this.reduce(function(previousValue, currentValue) { return previousValue + currentValue; }); return sum / this.length; };
Array.prototype.mean = function() { mean = 0; for (var i = 0; i < this.length; i++) { mean += this[i]; mean = mean / this.length; return mean; };