Function samples

Picks a given number of random elements from the array. It won't pick the same element twice (unless the array has duplicates).

If the number of elements to pick is greater than the array length, it will return the original array.

  • Type Parameters

    • T

    Parameters

    • array: T[]

      source array

    • elementsToPick: number

      number of elements to pick

    • allowShuffle: boolean = false

      if true, it will shuffle the values if elementsToPick is greater or equal to array length instead of returning the original array

    Returns T[]