2.0.2 • Published 9 years ago

running-average v2.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

running-average NPM version Bower Version Build Status Dependency Status

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 = require('running-average'); // or use window.RunningAverage in a browser w/out Require.js or Browserify

// create an instance
var runningAverage = new RunningAverage();

// push a number
runningAverage.push(1);

// or a few numbers
runningAverage.push(2, 3, 4);

// or an array of numbers
runningAverage.push([5, 6, 7]);

// get the current average any time you want
runningAverage.getAverage(); // => 4

// add some more numbers
runningAverage.push(8, 9);

// get an updated average 
runningAverage.getAverage(); // => 5

// oh, and it's chainable too!
runningAverage.push(10).push(11).getAverage(); // => 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

2.0.2

9 years ago

2.0.1

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago