Skip to main content

shuffle

Callable

  • shuffle<T>(xs: Traversable<T, unknown>, random?: () => number): T[]

  • It takes a traversable and returns a new array with the same elements in a random order.

    Example

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

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

    Type parameters

    • T

    Parameters

    • xs: Traversable<T, unknown>

      The array to shuffle.

    • random: () => number = Math.random

      The random implementation to shuffle

    Returns T[]

    A new array with the same elements as the original array, but in a random order.