Function: shuffle()
ts
function shuffle<T>(array): T[];Shuffles an array using Fisher-Yates algorithm. 使用Fisher-Yates算法打乱数组。
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
array | T[] | The array to shuffle / 要打乱的数组 |
Returns
T[]
A new shuffled array / 打乱后的新数组
Example
typescript
shuffle([1, 2, 3, 4, 5]) // => something like [3, 1, 5, 2, 4]
shuffle(['a', 'b', 'c']) // => something like ['c', 'a', 'b']Since
1.0.0