Code coverage report for array/shuffle.js

Statements: 100% (12 / 12)      Branches: 100% (2 / 2)      Functions: 100% (4 / 4)      Lines: 100% (11 / 11)     

All files » array/ » shuffle.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231         1 1   1 7 1   6 6 6     1     1    
define(['../random/randInt', './forEach'], function (randInt, forEach) {
 
    /**
     * Shuffle array items.
     */
    function shuffle(arr) {
        var result = [],
            rnd;
        forEach(arr, function(val, i, arr){
            if (!i) {
                result[0] = val;
            } else {
                rnd = randInt(0, i);
                result[i] = result[rnd];
                result[rnd] = val;
            }
        });
        return result;
    }
 
    return shuffle;
});