Code coverage report for array/split.js

Statements: 100% (11 / 11)      Branches: 100% (4 / 4)      Functions: 100% (3 / 3)      Lines: 100% (10 / 10)     

All files » array/ » split.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 271         1 5   5               5 10 10 10     5   1    
define(function() {
 
    /**
     * Split array into a fixed number of segments.
     */
    function split(array, segments) {
        segments = segments || 2;
 
        var output = [],
            segmentLength = Math.floor(array.length / segments),
            remainder = array.length % segments,
            start = 0,
            i = 0,
            n = array.length,
            len;
 
        while (start < n) {
            len = i++ < remainder ? segmentLength + 1 : segmentLength;
            output.push(array.slice(start, start + len));
            start += len;
        }
 
        return output;
    }
    return split;
});