List of utility methods to do Array Average
avarage()Array.prototype.avarage = function() return this.sum() / this.length; Array.prototype.sum = function() var sum = 0; for(var i = this.length; -- i >= 0 ;) sum += (this[i] === null || this[i] === undefined) ? 0 : this[i]; return sum; | |
average()Array.prototype.average = function() { var avg = 0; this.forEach(function(val) { avg += val; }); return avg / this.length; }; | |
average()Array.prototype.average = function () { return this.sum() / this.length | |
average()Array.prototype.average = function(){ return this.reduce( (a,b) => a + b, 0) / this.length | |
average()Array.prototype.average = function () { return this.sum() / this.length; }; console.log([1, 2, 3, 4].average()); | |
average()Array.prototype.average = function () { return (!this.length) ? NaN : this.reduce((acc, value) => { return acc + value; }) / this.length; }; | |
average()Array.prototype.average = function() if (this.length < 1) { return Number.NaN; return this.sum() / this.length; | |
average()Array.prototype.average = function () { var sum = 0, j = 0; for (var i = 0; i < this.length, isFinite(this[i]); i++) { sum += parseFloat(this[i]); ++j; return j ? sum / j : 0; }; | |
average()Array.prototype.average = function() { var sum = this.sum(); var count = this.length; return sum/count; | |
average()Array.prototype.average = function(){ var sum = 0; for (var i of this){ sum += i; return sum / this.length; |