Skip to content

Instantly share code, notes, and snippets.

@roidrage
Created March 29, 2011 08:19
Show Gist options
  • Save roidrage/891987 to your computer and use it in GitHub Desktop.
Save roidrage/891987 to your computer and use it in GitHub Desktop.
chunk.js
function chunk(a, s){
for(var x, i = 0, c = -1, l = a.length, n = []; i < l; i++)
(x = i % s) ? n[c][x] = a[i] : n[++c] = [a[i]];
return n;
}
function chunk(list, size) {
for(var position, i = 0, chunk = -1, chunks = []; i < list.length; i++) {
if (position = i % size) {
chunks[chunk][position] = list[i]
} else {
chunk++;
chunks[chunk] = [list[i]]
}
}
return chunks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment