UNPKG
@prelude/array
Version:
latest (3.0.0)
3.0.0
2.3.1
2.3.0
2.2.0
2.1.0
2.0.0
1.0.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.2
0.1.1
0.1.0
0.0.1
Array module.
@prelude/array
/
src
/
shuffle.ts
15 lines
(12 loc)
•
267 B
text/typescript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import
swap
from
'./swap.js'
/** In-place shuffle. */
const
shuffle = <T>(
values
: T[]): T[] => {
let
n = values.
length
while
(n) {
const
i =
Math
.
floor
(
Math
.
random
() * n--)
swap
(values, n, i) }
return
values }
export
default
shuffle