Skip to content

Instantly share code, notes, and snippets.

@toadkicker
Created September 18, 2014 13:39
Show Gist options
  • Save toadkicker/2ec47334d42cae7abfca to your computer and use it in GitHub Desktop.
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
Array.prototype.chunk = function (chunkSize) {
var array = this;
return [].concat.apply([],
array.map(function (elem, i) {
return i % chunkSize ? [] : [array.slice(i, i + chunkSize)];
})
);
}
@toadkicker
Copy link
Author

toadkicker commented Nov 1, 2021

Takes a large array and creates sets of arrays by chunk size. If you don't like patching Array, just assign const chunk = function ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment