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 27 | 1 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; }); |