array-misc
Array utils
- Shifts array element up, down or custom
- Group array by property
- Find common values in two arrays
- Find not common values in two arrays
- Find array values not found in other array
Installation
$ npm install array-misc
Usage
// Importvar arrayMisc = ;arrayMisc;
up
var arr = 12345; arrayMisc;console; // -> [1,2,3,5,4]
down
var arr = 12345; arrayMisc;console; // -> [2,1,3,4,5]
custom
var arr = 12345; arrayMiscconsole; // -> [2,3,4,5,1]
removeItem
var arr = 12345; arrayMiscconsole; // -> [1,3,4,5]
getElementsNotFoundInOtherArrayByComparingPropValues
var arr = id:"1" title:"First"id:"2" title:"Second"id:"3" title:"Third";var otherArr = id:"2" title:"Second"id:"3" title:"Third"id:"4" title:"Fourth";var result = arrayMisc;console // => [{id:"4", title:"Fourth"}]
filterArrayPropValuesByOtherArrayPropValues
var arr = id:"1" title:"First"id:"2" title:"Second"id:"3" title:"Third";var otherArr = objectId:"2" title:"Second"objectId:"3" title:"Third"objectId:"4" title:"Fourth";var result = arrayMisc;console // => [{id:"2", title:"Second"},{id:"3", title:"Third"}]
groupBy
var arr = type:"orange" title:"First" type:"orange" title:"Second" type:"banana" title:"Third" type:"banana" title:"Fourth";var gB = ; // => {orange:[...], banana:[...]}gBorange; // => [{"type":"orange","title":"First"},{"type":"orange","title":"Second"}]gBbanana; // => [{"type":"banana","title":"Third"},{"type":"banana","title":"Fourth"}]
findCommonValues, findNotCommonValues, findArrValuesNotFoundInOtherArr
var arrMisc = ; var array1 = "arr1" "arr2""common3""arr3" "common1" "common2" "arr4" "arr5" "arr6";var array2 = "arrOther1" "arrOther2""common1" "common2" "common3" "extra"; arrMisc;arrMisc;arrMisc;arrMisc; // Output// ["common1", "common2", "common3"]// ["arr1", "arr2", "arr3", "arr4", "arr5", "arr6", "arrOther1", "arrOther2", "extra"]// ["arr1", "arr2", "arr3", "arr4", "arr5", "arr6"]// ["arrOther1", "arrOther2", "extra"]