UNPKG

aggregate-functions

Version:

JavaScript library to get aggregate values of array, namely; SUM, AVG, MAX, MIN, COUNT

81 lines (48 loc) 1.5 kB
# 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: ```javascript const aggregateFunctions = require("aggregate-functions"); ``` #### Use in method ```javascript //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 ```javascript 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 ```