feat(p2p): random peer exchange

This commit is contained in:
Alexey Kasyanchuk
2018-04-05 09:11:12 +03:00
parent 5daf9f5c65
commit fac6736710
2 changed files with 17 additions and 2 deletions

14
src/background/shuffle.js Normal file
View 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
}