Namespace: list

Functions

arrayToRecord

arrayToRecord<ArrayItemT, RecordItemT, KeyT>(array, key, map): Record<ArrayItemT[KeyT], RecordItemT>

Helper for mapping arrays with named items to records. Note that if there are items with the same key the last one will overwrite the earlier ones.

Type parameters

Name Type
ArrayItemT extends Record<string, any>
RecordItemT RecordItemT
KeyT extends string | number | symbol

Parameters

Name Type Description
array ArrayItemT[] Array with named items
key KeyT Name of the property to use for the record key
map (item: ArrayItemT) => RecordItemT Function for mapping the items

Returns

Record<ArrayItemT[KeyT], RecordItemT>


arrayToRecordConcat

arrayToRecordConcat<ArrayItemT, RecordItemT, KeyT>(array, key, map): Record<ArrayItemT[KeyT], RecordItemT[]>

Helper for mapping arrays with named items to records. Unlike arrayToRecord which overwrites duplicate keys arrayToRecordConcat concatenates them in an array. Note that even non-duplicate entries are placed in an array with length 1.

Type parameters

Name Type
ArrayItemT extends Record<string, any>
RecordItemT RecordItemT
KeyT extends string | number | symbol

Parameters

Name Type Description
array readonly ArrayItemT[] Array with named items
key KeyT Name of the property to use for the record key
map (item: ArrayItemT) => RecordItemT Function for mapping the items

Returns

Record<ArrayItemT[KeyT], RecordItemT[]>


createPopper

createPopper<T>(list): () => undefined | T(count: number) => T[]

Returns a function that pops elements from the beginning of the list until the list is empty.

Type parameters

Name
T

Parameters

Name Type
list T[]

Returns

fn

▸ (): undefined | T

Returns

undefined | T

▸ (count): T[]

Parameters
Name Type
count number
Returns

T[]


createRandomPopper

createRandomPopper<T>(list): () => undefined | T(count: number) => T[]

Returns a function that pops random elements from the list until the list is empty.

Type parameters

Name
T

Parameters

Name Type
list T[]

Returns

fn

▸ (): undefined | T

Returns

undefined | T

▸ (count): T[]

Parameters
Name Type
count number
Returns

T[]


fill

fill<T>(count, callback): T[]

Generate a new array filled with elements generated by a callback function.

Type parameters

Name
T

Parameters

Name Type Description
count number Size of the new array
callback (index: number) => T The callback function to create each element

Returns

T[]