running-average
Memory-efficient module that tracks the average value of an unlimited quantity of numbers
Install
$ npm install --save running-average
or
$ bower install approximate-number
Usage
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 average runningAverage; // => 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.
License
MIT © Nathan Friedly