Nodejs Array Average average()

Here you can find the source of average()

Method Source Code

Array.prototype.average = function(){
   var sum = 0;//www .  j  a  va  2s.c  om
   for (var i of this){
      sum += i;
   }

   return sum / this.length;
}

Related

  1. average()
    Array.prototype.average = function () {
      return this.sum() / this.length;
    };
    console.log([1, 2, 3, 4].average());
    
  2. average()
    Array.prototype.average = function () {
      return (!this.length) ? NaN : this.reduce((acc, value) => {
        return acc + value;
      }) / this.length;
    };
    
  3. average()
    Array.prototype.average = function()
      if (this.length < 1) {
          return Number.NaN;
      return this.sum() / this.length;
    
  4. 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;
    };
    
  5. average()
    Array.prototype.average = function() {
      var sum = this.sum();
      var count = this.length;
      return sum/count;
    
  6. average(arr)
    Array.prototype.average = function(arr) {
      if(!arr) arr = this;
      var len =  arr.length, i, avg = 0;
      for( i = 0; i < len; i++ ) {
        avg += arr[i];
      return avg / len;
    
  7. average(fun)
    Array.prototype.average = function (fun) {
        return this.sum(fun) / this.length;
    };
    
  8. avg()
    Array.prototype.avg = function(){
      return this.sum() / this.length;
    };
    Array.prototype.sum = function(){
      for (var i = 0, sum = 0 ; i != this.length; ++i) {
        var n = this[i];
        if(!isNaN(n)) {
          sum += n*1;
      return sum;
    };
    
  9. avg()
    Array.prototype.avg = function() {
      var av, num, _i, _len;
      av = 0;
      for (_i = 0, _len = this.length; _i < _len; _i++) {
        num = this[_i];
        av = av + num;
      return av / this.length;
    };
    ...