Skip to content

Instantly share code, notes, and snippets.

@jonchurch
Created July 23, 2019 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonchurch/6d4622fdea4a6233bcc866e483063e51 to your computer and use it in GitHub Desktop.
Save jonchurch/6d4622fdea4a6233bcc866e483063e51 to your computer and use it in GitHub Desktop.
Array Chonk (Array chunking)
function chonkArray(array, chonkSize) {
let arrayOfChonks = [];
for (let i = 0; i < array.length; i += chonkSize) {
const chonk = array.slice(i, i + chonkSize);
arrayOfChonks.push(chonk);
}
return arrayOfChonks;
}
const chonkable = ["πŸ•","🐑","🍝","πŸ™","✨"]
chonkArray(chonkable, 2)
// [ ["πŸ•","🐑"],["🍝","πŸ™"],["✨"] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment