Created
November 6, 2012 19:35
-
-
Save shesek/4026949 to your computer and use it in GitHub Desktop.
Chunk an array and pass each chunk to callback
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
# Chunk an array into multiple chunks with a given size, and pass | |
# each chunk to a callback. This is done that way, instead of creating | |
# an array of all the chunks, so that big arrays can be chunked without | |
# having the store all the chunks in memory. | |
chunk = (arr, size, fn) -> | |
i = 0 | |
fn arr.slice i, i+=size while i < arr.length | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment