File: index.js

package info (click to toggle)
node-mess 0.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 76 kB
  • ctags: 2
  • sloc: makefile: 2; sh: 2
file content (19 lines) | stat: -rw-r--r-- 562 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(function(module) {
    // see https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
    // and http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript#6274398
    module.exports = function shuffle(array) {
        var counter = array.length,
            temp,
            index;

        while (counter) {
            index = Math.floor(Math.random() * counter--);

            temp = array[counter];
            array[counter] = array[index];
            array[index] = temp;
        }

        return array;
    }
})(module);