Created
May 5, 2010 13:28
-
-
Save jakubpawlowicz/390760 to your computer and use it in GitHub Desktop.
MooTools Array inGroupsOf method. Returns array of arrays grouped by <size> elements.
This file contains 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
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