Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created September 5, 2012 13:41
Show Gist options
  • Save Sephi-Chan/3636726 to your computer and use it in GitHub Desktop.
Save Sephi-Chan/3636726 to your computer and use it in GitHub Desktop.
window.inGroupsOf = function(array, number, fillWith) {
fillWith = fillWith || null;
var index = -number, slices = [];
if (number < 1) return array;
while ((index += number) < array.length) {
var s = array.slice(index, index + number);
while(s.length < number)
s.push(fillWith);
slices.push(s);
}
return slices;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment