Skip to content

subset

subset<T>(items, p): T[]

Defined in: src/global/collections.ts:266

Each element kept independently with probability p.

The result has no fixed length: it is a coin flip per element, so the size varies around items.length * p. Order is preserved.

T

Collection<T>

number

T[]

subset([1, 2, 3, 4, 5, 6], 0.5); // [ 1, 4, 5 ]