Skip to content

Instantly share code, notes, and snippets.

@jakubpawlowicz
Created May 5, 2010 13:28
Show Gist options
  • Save jakubpawlowicz/390760 to your computer and use it in GitHub Desktop.
Save jakubpawlowicz/390760 to your computer and use it in GitHub Desktop.
MooTools Array inGroupsOf method. Returns array of arrays grouped by <size> elements.
Array.implement({
inGroupsOf: function(size) {
var slices = [];
var current = [];
this.each(function(e) {
if (current.length < size) current.push(e);
else {
slices.push(current);
current = [e];
}
});
slices.push(current);
return slices;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment