Home Reference Source

Function

Static Public Summary
public

Sorts the array according to .valueOf().

public

concatArrays(accumulator: any[], value: any)

Shallow flat operation.

public

concatNestedArrays(accumulator: any[], value: any)

Deep flat operation.

public

isDefined(value: any)

Filters out all undefined values.

public

isNotEmptyString(value: any)

Filters out all empty strings.

public

keepUniqueDates(date: Date, index: number, array: Date[])

Filters out all duplicate dates.

public

keepUniqueValues(value: any, index: number, array: any[])

Filters out all duplicate values.

public

mergeObjects(accumulator: object, value: any)

Creates an object with all properties found in the array.

public

sumNumbers(accumulator: number, value: number)

Sum all values.

Static Public

public ascendingDates(a: Date, b: Date) source

import ascendingDates from '@fkm/array'

Sorts the array according to .valueOf().

Params:

NameTypeAttributeDescription
a Date

The first element for comparison.

b Date

The second element for comparison.

Example:

[
  new Date(2020, 0, 4),
  new Date(2020, 0, 2),
  new Date(2020, 0, 1),
  new Date(2020, 0, 3),
].sort(ascendingDates)
// [
//   new Date(2020, 0, 1),
//   new Date(2020, 0, 2),
//   new Date(2020, 0, 3),
//   new Date(2020, 0, 4),
// ];

public concatArrays(accumulator: any[], value: any) source

import concatArrays from '@fkm/array'

Shallow flat operation.

Params:

NameTypeAttributeDescription
accumulator any[]

The accumulated value previously returned in the last invocation.

value any

The current element being processed in the array.

Example:

[[1, 2], [[3], 4]].reduce(concatArrays, []) // [1, 2, [3], 4]

See:

public concatNestedArrays(accumulator: any[], value: any) source

import concatNestedArrays from '@fkm/array'

Deep flat operation.

The depth is unlimited and cannot be set.

Params:

NameTypeAttributeDescription
accumulator any[]

The accumulated value previously returned in the last invocation.

value any

The current element being processed in the array.

Example:

[[1, 2], [[3], 4]].reduce(concatNestedArrays, []) // [1, 2, 3, 4]

See:

public isDefined(value: any) source

import isDefined from '@fkm/array'

Filters out all undefined values.

Params:

NameTypeAttributeDescription
value any

The current element being processed in the array.

Example:

[1, 2, , 4].filter(isDefined) // [1, 2, 4]

public isNotEmptyString(value: any) source

import isNotEmptyString from '@fkm/array'

Filters out all empty strings.

Params:

NameTypeAttributeDescription
value any

The current element being processed in the array.

Example:

['a', 'b', '', 'd'].filter(isNotEmptyString) // ['a', 'b', 'd']

public keepUniqueDates(date: Date, index: number, array: Date[]) source

import keepUniqueDates from '@fkm/array'

Filters out all duplicate dates.

The .valueOf() is used to determine if dates are equal.

Params:

NameTypeAttributeDescription
date Date

The current element being processed in the array.

index number

The index of the current element being processed in the array.

array Date[]

The array filter was called upon.

Example:

[
  new Date(2020, 0, 1),
  new Date(2020, 0, 2),
  new Date(2020, 0, 2),
  new Date(2020, 0, 4),
].filter(keepUniqueDates)
// [
//   new Date(2020, 0, 1),
//   new Date(2020, 0, 2),
//   new Date(2020, 0, 4),
// ]

public keepUniqueValues(value: any, index: number, array: any[]) source

import keepUniqueValues from '@fkm/array'

Filters out all duplicate values.

Params:

NameTypeAttributeDescription
value any

The current element being processed in the array.

index number

The index of the current element being processed in the array.

array any[]

The array filter was called upon.

Example:

[1, 2, 2, 4].filter(keepUniqueValues) // [1, 2, 4]

public mergeObjects(accumulator: object, value: any) source

import mergeObjects from '@fkm/array'

Creates an object with all properties found in the array.

Params:

NameTypeAttributeDescription
accumulator object

The accumulated value previously returned in the last invocation.

value any

The current element being processed in the array.

Example:

 [{ a: 1 }, { b: 2 }].reduce(mergeObjects, {}) // { a: 1, b: 2 }

public sumNumbers(accumulator: number, value: number) source

import sumNumbers from '@fkm/array'

Sum all values.

Params:

NameTypeAttributeDescription
accumulator number

The accumulated value previously returned in the last invocation.

value number

The current element being processed in the array.

Example:

[1, 2, 3].reduce(sumNumbers, 0) // 6