JS累加器

匿名 (未验证) 提交于 2019-12-03 00:43:02
 function Accumulator(){      var average = 0;     var length = 0;     var arr = [];     var sum = 0;     var max = Number.NEGATIVE_INFINITY;     var min = Number.POSITIVE_INFINITY;      this.add = function(val){         length++;         average = average + ( val - average ) / length;         sum += val;         if(val > max){             max = val;         }         if(val < min){             min = val;         }         arr.push(val);     }      this.size = function(){         return length;     }      this.getAverage = function(){         return average;     }      this.sum = function(){         return sum;     }      this.max = function(){         return max;     }      this.min = function(){         return min;     } }
文章来源: JS累加器
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!