Created
February 16, 2012 22:36
-
-
Save haldun/1848412 to your computer and use it in GitHub Desktop.
Split an array into evenly sized subarrays
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
var chunk = function(array, n) { | |
var retval = []; | |
for (var i = 0, len = array.length; i < len; i += n) { | |
retval.push(array.slice(i, i + n)); | |
} | |
return retval; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment