shuffle

collection

Creates an array of shuffled values, using a version of the Fisher-Yates shuffle.

Signature

shuffle<T>(collection: T[]): T[]

Parameters

NameTypeDescription
collectionT[]The collection to shuffle

Returns

T[] - Returns the new shuffled array

Examples

Shuffle array

import { shuffle } from 'dashlite'

const result = shuffle([1, 2, 3, 4])
console.log(result)

Output:

[4, 1, 3, 2] (order varies)

Shuffle strings

import { shuffle } from 'dashlite'

const result = shuffle(['a', 'b', 'c', 'd'])
console.log(result)

Output:

['c', 'a', 'd', 'b'] (order varies)

Available since version 1.2.0