Created
March 29, 2011 08:19
-
-
Save roidrage/891987 to your computer and use it in GitHub Desktop.
chunk.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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