Created
May 11, 2012 17:57
-
-
Save kyledecot/2661361 to your computer and use it in GitHub Desktop.
jQuery.each_slice inspired by Ruby's each_slice
This file contains hidden or 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
(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