Skip to content

Instantly share code, notes, and snippets.

@shesek
Created November 6, 2012 19:35
Show Gist options
  • Save shesek/4026949 to your computer and use it in GitHub Desktop.
Save shesek/4026949 to your computer and use it in GitHub Desktop.
Chunk an array and pass each chunk to callback
# 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