Skip to content

Instantly share code, notes, and snippets.

@lambdaX
Created September 4, 2014 07:24
Show Gist options
  • Save lambdaX/9bb87f5b1ea9c9ff01bd to your computer and use it in GitHub Desktop.
Save lambdaX/9bb87f5b1ea9c9ff01bd to your computer and use it in GitHub Desktop.
My way to chunk an Array
Array.prototype.chunk = function (n) {
return this.reduce(function (g,v,i) {
var chunk = (i-i%n) / n;
if (!(i%n)) g[chunk] = [];
g[chunk].push(v);
return g;
},[]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment