JSPM

running-average

2.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q28144F
  • License MIT

Memory-efficient module that tracks the average value of an unlimited quantity of numbers

Package Exports

  • running-average

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (running-average) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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