@eroyeroy/utils - v0.1.0
    Preparing search index...

    Function shuffleArray

    • Returns a new array with elements in a random order (Fisher-Yates shuffle). Pass a custom random function to make the shuffle deterministic in tests.

      Type Parameters

      • T

      Parameters

      • array: readonly T[]

        The source array.

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

        RNG function returning [0, 1). Defaults to Math.random.

      Returns T[]

      shuffleArray([1, 2, 3, 4, 5]) // => e.g. [3, 1, 5, 2, 4]