Skip to content

Instantly share code, notes, and snippets.

@kyledecot
Created May 11, 2012 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kyledecot/2661361 to your computer and use it in GitHub Desktop.
Save kyledecot/2661361 to your computer and use it in GitHub Desktop.
jQuery.each_slice inspired by Ruby's each_slice
(function($) {
$.each_slice = function(num, things, iterator) {
var tmp = [];
$.each(things, function(index, thing) {
tmp.push(thing);
if (tmp.length >= num || (index + 1) >= things.length) {
iterator(tmp);
tmp = [];
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment