array-means
TypeScript icon, indicating that this package has built-in type declarations

2.5.0 • Public • Published

array-means

Calculates various averages of an array

Installation

For Node.js run the following command:

npm i array-means

For Yarn run the following command:

yarn add array-means

Browser environment

Download the latest version of array-means here.

Usage

Node.js environment

const {
  arithmetic,
  cubic,
  geometric,
  harmonic,
  quadratic,
  median,
} = require("array-means");

Arithmetic mean

Wikipedia article of Arithmetic mean

var amean = arithmetic([10, 25, 50]);
// amean => 28.333333333333332

Quadratic mean

Wikipedia article of Quadratic mean

var qmean = quadratic([10, 25, 50]);
// qmean => 32.78719262151

Harmonic mean

Wikipedia article of Harmonic mean

var hmean = harmonic([10, 25, 50]);
// hmean => 18.75

Geometric mean

Wikipedia article of Geometric mean

var gmean = geometric([10, 25, 50]);
// gmean => 23.20794417

Cubic mean

Wikipedia article of Cubic mean

var cmean = cubic([10, 25, 50]);
// cmean => 36.14150411

Median

Wikipedia article of Median

var medianResult = median([10, 25, 50]);
// medianResult => 25

Benchmarks

Algorithm Operations per second Tolerance
arithmetic 90,273,949 ops/sec ±0.40%
quadratic 45,955,194 ops/sec ±1.35%
harmonic 142,704,156 ops/sec ±0.33%
geometric 116,823,047 ops/sec ±0.20%
cubic 786,168 ops/sec ±0.12%
median 3,392,087 ops/sec ±0.21%

Tested on an AMD Ryzen 7 5800X using Node.js v16.13.2 on Windows 10 (21H1)

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see here for more details.

Dependencies (0)

    Dev Dependencies (16)

    Package Sidebar

    Install

    npm i array-means

    Weekly Downloads

    5

    Version

    2.5.0

    License

    MIT

    Unpacked Size

    13.6 kB

    Total Files

    24

    Last publish

    Collaborators

    • bikossor