MCPcopy Create free account
hub / github.com/d3/d3-array / shuffler

Function shuffler

src/shuffle.js:3–13  ·  view source on GitHub ↗
(random)

Source from the content-addressed store, hash-verified

1export default shuffler(Math.random);
2
3export function shuffler(random) {
4 return function shuffle(array, i0 = 0, i1 = array.length) {
5 let m = i1 - (i0 = +i0);
6 while (m) {
7 const i = random() * m-- | 0, t = array[m + i0];
8 array[m + i0] = array[i + i0];
9 array[i + i0] = t;
10 }
11 return array;
12 };
13}

Callers 2

shuffle-test.jsFile · 0.85
shuffle.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected