Skip to content

Instantly share code, notes, and snippets.

@haldun
Created February 16, 2012 22:36
Show Gist options
  • Save haldun/1848412 to your computer and use it in GitHub Desktop.
Save haldun/1848412 to your computer and use it in GitHub Desktop.
Split an array into evenly sized subarrays
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