Function sampleSize

  • Gets n random elements at unique keys from array up to the size of array.

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array to sample.

    • Optionaln: number

      The number of elements to sample.

    Returns T[]

    Returns the random elements.

    4.0.0

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

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