Skip to content

Function: pick()

Overload 1

pick<T>(array): T | null

Defined in: collection.ts:17

Picks an item at random from an array.

Type Parameters

T

T

Parameters

array

readonly T[]

The array from which the item will be picked.

Returns

T | null

Returns the picked item or null if the array is empty.

Example

ts
pick(['A', 'B', 'C'])  // "A", "B" or "C"

Overload 2

pick<T>(set): T | null

Defined in: collection.ts:30

Picks an item at random from a collection.

Type Parameters

T

T

Parameters

set

Set<T>

The collection from which the item will be picked.

Returns

T | null

Returns the picked item or null if the collection is empty.

Example

ts
const collection = new Set()
collection.add('A')
collection.add('B')
collection.add('C')
pick(collection)  // "A", "B" or "C"

Overload 3

pick<K, V>(map): V | null

Defined in: collection.ts:43

Picks an item at random from a collection.

Type Parameters

K

K

V

V

Parameters

map

Map<K, V>

The collection from which the item will be picked.

Returns

V | null

Returns the picked item or null if the collection is empty.

Example

ts
const collection = new Map()
collection.set(1, 'A')
collection.set(2, 'B')
collection.set(3, 'C')
pick(collection)  // "A", "B" or "C"