12345678910111213141516171819202122232425262728 |
- var randInt = require('../random/randInt');
- /**
- * Shuffle array items.
- */
- function shuffle(arr) {
- var results = [],
- rnd;
- if (arr == null) {
- return results;
- }
- var i = -1, len = arr.length, value;
- while (++i < len) {
- if (!i) {
- results[0] = arr[0];
- } else {
- rnd = randInt(0, i);
- results[i] = results[rnd];
- results[rnd] = arr[i];
- }
- }
- return results;
- }
- module.exports = shuffle;
|