Created
September 18, 2014 13:39
-
-
Save toadkicker/2ec47334d42cae7abfca to your computer and use it in GitHub Desktop.
takes a large array, splitting into an array of arrays based on chunkSize
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
Array.prototype.chunk = function (chunkSize) { | |
var array = this; | |
return [].concat.apply([], | |
array.map(function (elem, i) { | |
return i % chunkSize ? [] : [array.slice(i, i + chunkSize)]; | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Takes a large array and creates sets of arrays by chunk size. If you don't like patching Array, just assign
const chunk = function ...