New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

srol

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

srol

Class maintaining a rolling average.

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

srol NPM version NPM total downloads

Maintaining a simple dynamic rolling average.

The rolling average is the unweighted mean of the previous i numbers where i is the length or argument of the rolling average.

Install

Install with npm:

$ npm install --save srol

Usage

let srol = require('srol');

To create a rolling average of length n use:

let rollingAverage = new srol(n);

Methods

add

To add a number, or an array of numbers, to the rolling average use:

rollingAverage.add(n);

add will throw a TypeError if n is not a number or an array containing not a number.

average

Getter that returns the average of the last rollingAverage.length numbers.

rollingAverage.average;

Example

Simple example or test of the rolling average.

let rollingAverage = new srol(3);
rollingAverage.add(5);

Since there is only 1 number in the array, the average will be 5.

rollingAverage.add(4);
rollingAverage.add(6);

Now the array is 'full' and the average will be 5, (4+5+6)/3.

rollingAverage.add(7);

The first number, 5, is replaced by a 7 and the average becomes 6.

> rollingAverage.average;
6

Running Tests

Test cover the basic function and requirements of the rolling average.

$ npm install && npm test

Contributing

Pull requests are always welcome.

Keywords

average

FAQs

Package last updated on 13 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts