JSPM

running-average

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

Memory-efficient module that accepts an unlimited quantity of numbers and returns the average of the most recent n 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 Build Status Dependency Status

Memory-efficient module that accepts an unlimited quantity of numbers and returns the average of the most recent n numbers

Install

$ npm install --save running-average

Usage

var RunningAverage = require('running-average');

// create an instance
var runningAverage = new RunningAverage({
  windowSize: 4 // how many recent numbers to consider when calculating average (default is 100)
});

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

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

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

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

// get an updated average (which only takes into account the last `windowSize` numbers)
runningAverage.getAverage(); // => 4

// oh, and it's chainable too!
runningAverage.push(1).push(3).getAverage(); // => 3

License

MIT © Nathan Friedly