UNPKG

@prelude/array

Version:

Array module.

11 lines (8 loc) 278 B
import randomIndex from './random-index.js' /** @returns random element or `undefined` if array is empty. */ const maybeSample = <T>(values: T[]): undefined | T => values.length > 0 ? values[randomIndex(values.length)] : undefined export default maybeSample