• Shuffles an input array and returns a copy of it. Uses the modern Fisher-Yates shuffle algorithm to generate a random permutation of the input array.

    Remarks

    The input array is not modified.

    Example

    shuffle(['foo', 'bar', 'baz'])
    // => { ok: true, value: shuffled copy of the array }

    Example

    Handle an invalid input:

    shuffle('not an array')
    // => { ok: false, value: error: Error('[collections.shuffle] Input is not an array') }

    Type Parameters

    • const T extends string | number | boolean

      The type of the elements in the array.

    Parameters

    • arr: T[]

      The array to shuffle.

    Returns Result<T[], Error>

    A Result object with either the shuffled array if ok, or an Error object if the provided input is not an array

Generated using TypeDoc v0.24.7