feat(p2p): random peer exchange
This commit is contained in:
14
src/background/shuffle.js
Normal file
14
src/background/shuffle.js
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Shuffles array in place.
|
||||
* @param {Array} a items An array containing the items.
|
||||
*/
|
||||
export default function shuffle(a) {
|
||||
let j, x, i;
|
||||
for (i = a.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
x = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = x;
|
||||
}
|
||||
return a
|
||||
}
|
Reference in New Issue
Block a user