Options
All
  • Public
  • Public/Protected
  • All
Menu

Module sampleSize

Index

References

Functions Array

References

Renames and re-exports sampleSize

Array Functions

  • sampleSize<T>(collection: Collection<T>, n?: number, guard?: any): T[]
  • Gets n random elements at unique keys from array up to the size of array.

    since

    5.11.0

    example
    sampleSize([1, 2, 3], 2)
    // => [3, 1]

    sampleSize([1, 2, 3], 4)
    // => [2, 3, 1]

    Type parameters

    • T

    Parameters

    • collection: Collection<T>

      The array to sample.

    • n: number = 1

      The number of elements to sample.

    • Optional guard: any

    Returns T[]

    Returns the random elements.