Memory-efficient module that tracks the average value of an unlimited quantity of numbers
$ npm install --save running-average
$ bower install approximate-number
var RunningAverage = ; // or use window.RunningAverage in a browser w/out Require.js or Browserify// create an instancevar runningAverage = ;// push a numberrunningAverage;// or a few numbersrunningAverage;// or an array of numbersrunningAverage;// get the current average any time you wantrunningAverage; // => 4// add some more numbersrunningAverage;// get an updated averagerunningAverage; // => 5// oh, and it's chainable too!runningAverage; // => 6
Also see version 1.0 for a
windowSize option to limit the average to the last n numbers, but be aware that it uses a less efficient algorithm.
MIT © Nathan Friedly