File

projects/m2-core/src/lib/core/utils/array.utils.ts

Index

Methods

Methods

Static arrayToMap
arrayToMap(array: T[], property)
Type parameters :
  • T
Parameters :
Name Type Optional Default value
array T[] No
property No 'id' as any
Returns : Map<any, T>
Static arrayToMapExt
arrayToMapExt(array: I[], keyMapper: (item: I) => void, valueMapper: (item: I) => void)
Type parameters :
  • I
  • K
  • V
Parameters :
Name Type Optional
array I[] No
keyMapper function No
valueMapper function No
Returns : Map<K, V>
Static arrayToMapFnKeyMapper
arrayToMapFnKeyMapper(array: V[], keyMapper: (item: V) => void)
Type parameters :
  • K
  • V
Parameters :
Name Type Optional
array V[] No
keyMapper function No
Returns : Map<K, V>
Static createIntArray
createIntArray(from: number, to: number)

Creates sequential array of integers within the specified borders according to the following schema: [from; to) {Array}

Parameters :
Name Type Optional
from number No
to number No
Returns : number[]
Static diffArrays
diffArrays(arr1: T[], arr2: T[], getKeyFn?: (item?: T) => void)
Type parameters :
  • T

Method assumes that arrays contain unique items in terms of getKeyFn (item => item by default).

Parameters :
Name Type Optional
arr1 T[] No
arr2 T[] No
getKeyFn function Yes
Returns : literal type
Static equalContent
equalContent(a1: T[], a2: T[], equalsFn?: (i1?: T,i2?: T) => void)
Type parameters :
  • T
Parameters :
Name Type Optional
a1 T[] No
a2 T[] No
equalsFn function Yes
Returns : boolean
Static find
find(arr: T[], predicate: (item: T) => void)
Type parameters :
  • T
Parameters :
Name Type Optional
arr T[] No
predicate function No
Returns : ArrayElement<T>
Static findDominant
findDominant(values: T[])
Type parameters :
  • T
Parameters :
Name Type Optional
values T[] No
Returns : T
Static findFromEnd
findFromEnd(arr: T[], predicate: (item: T) => void)
Type parameters :
  • T
Parameters :
Name Type Optional
arr T[] No
predicate function No
Returns : T
Static findOrAdd
findOrAdd(arr: T[], target: T, prop: string, toTheBeginnng)
Type parameters :
  • T

Joins arrays, filters out duplicates and sets 'partiallyApplied' field

Parameters :
Name Type Optional Default value
arr T[] No
target T No
prop string No 'id'
toTheBeginnng No false
Returns : T
Static getChunks
getChunks(arr: T[], chunkSize: number)
Type parameters :
  • T
Parameters :
Name Type Optional
arr T[] No
chunkSize number No
Returns : [][]
Static getLast
getLast(arr: T[])
Type parameters :
  • T
Parameters :
Name Type Optional
arr T[] No
Returns : T
Static getUnique
getUnique(a: T[])
Type parameters :
  • T
Parameters :
Name Type Optional
a T[] No
Returns : T[]
Static getUniqueKeys
getUniqueKeys(arr: T[], keyMapper: (item: T) => void)
Type parameters :
  • T
  • K
Parameters :
Name Type Optional
arr T[] No
keyMapper function No
Returns : K[]
Static groupBy
groupBy(array: T[], keyMapper: (item: T) => void, valueMapper?: (item?: T) => void, filterFn?: (item?: T) => void)
Type parameters :
  • T
  • K
  • V
Parameters :
Name Type Optional
array T[] No
keyMapper function No
valueMapper function Yes
filterFn function Yes
Returns : Map<K, V[]>
Static groupToStringMap
groupToStringMap(array: T[], keyMapper: (item: T) => void, valueMapper?: (item?: T) => void)
Type parameters :
  • T
  • V
Parameters :
Name Type Optional
array T[] No
keyMapper function No
valueMapper function Yes
Returns : StringMap<V[]>
Static isEmpty
isEmpty(array: Array)
Parameters :
Name Type Optional
array Array<any> No
Returns : boolean
Static joinArrays
joinArrays(arrays: T[][], separator?: S)
Type parameters :
  • T
  • S
Parameters :
Name Type Optional
arrays T[][] No
separator S Yes
Returns : Array<T | S>
Static pickElementByName
pickElementByName(array: V[], name: string, seed: number)
Type parameters :
  • V
Parameters :
Name Type Optional Default value
array V[] No
name string No
seed number No 0
Returns : V
Static remove
remove(array: T[], predicate: (item: T,index: number) => void, firstOnly)
Type parameters :
  • T

Removes elements from the array that satisfy the predicate. {T[]} Array of removed elements.

Parameters :
Name Type Optional Default value
array T[] No
predicate function No
firstOnly No false
Returns : T[]
Static sort
sort(list: Array, propertyName: string, asc)
Parameters :
Name Type Optional Default value
list Array<any> No
propertyName string No
asc No true
Returns : void
Static sortCriteria
sortCriteria(criteria: Option[])

Pushes "name" criteria to top

Parameters :
Name Type Optional
criteria Option[] No
Returns : void
Static toArray
toArray(elem: T | T[])
Type parameters :
  • T
Parameters :
Name Type Optional
elem T | T[] No
Returns : T[]

results matching ""

    No results matching ""