array-function-operations
v1.0.5
Published
This npm package provides a collection of useful array operation functions. It is lightweight because we are not using any outside dependencies.
Downloads
4
Readme
array-operations
This npm package provides a collection of useful array operation functions. It is lightweight because we are not using any outside dependencies.
Installation
npm install array-function-operations
operations
Main array functions are :
sum(arr){
- array must be non empty }
average(arr){
- array must be non empty }
countOccurrences(arr, sortOrder){
- arr = ['apple','mango','apple']
- output = { mango: 1, apple: 2 } }
bulkUpdateArrayElements(arr, elementToUpdate, newElement) {
- arr = ['apple','mango','apple'] , elementToUpdate = 'apple' , newElement = 'apples'
- output = ['apples','mango','apples'] }
sortElements(arr, sortOrder) {
- arr = ['apple','mango','apple'] , sortOrder = 'desc'
- output = ['mango','apples','apples'] }
isArrayNumbered(arr){
- arr = ['apple','mango',4]
- output = false
- arr = [1,2,3]
- output = true }
isArrayString(arr){
- arr = ['apple','mango',4]
- output = false
- arr = ['1','2','3']
- output = true }
groupByAndCountObjects(arr,groupBy,sortOrder){
- arr = [{name:"apple",useedBy:"people"},{name:"apple",usedBy:"animals"},{name:"orrange",usedBy:"people"}] , groupBy=name,sortOrder='desc'
- output = [{name:"apple",count:2},{name:"orrange",count:1}] }