aggregate-functions
v1.0.1
Published
JavaScript library to get aggregate values of array, namely; SUM, AVG, MAX, MIN, COUNT
Downloads
19
Maintainers
Readme
aggregate-functions
JavaScript library to get aggregate values of array, namely; SUM, AVG, MAX, MIN, COUNT.
Node.js (Install)
Requirements:
Node.js
npm (Node.js package manager)
npm i aggregate-functions
Or
npm i aggregate-functions --save
Usage
Modular include:
const aggregateFunctions = require("aggregate-functions");
Use in method
//for getting SUM of an array
let sum = aggregateFunctions.sum(array);
//for getting AVG of an array
let avg = aggregateFunctions.avg(array);
//for getting MAX of an array
let max = aggregateFunctions.max(array);
//for getting MIN of an array
let min = aggregateFunctions.min(array);
//for getting COUNT/LENGTH of an array
let count = aggregateFunctions.count(array);
SOME EXAMPLES
let exapmpleArray = [7, 20, 24, 14, 2, 19, 12]
//for getting SUM of an array
let sum = aggregateFunctions.sum(exapmpleArray);
console.log(sum);//98
//for getting AVG of an array
let avg = aggregateFunctions.avg(exapmpleArray);
console.log(avg);//14
//for getting MAX of an array
let max = aggregateFunctions.max(exapmpleArray);
console.log(max);//24
//for getting MIN of an array
let min = aggregateFunctions.min(exapmpleArray);
console.log(min);//2
//for getting COUNT/LENGTH of an array
let count = aggregateFunctions.count(exapmpleArray);
console.log(count);//7