Created
July 23, 2019 21:35
-
-
Save jonchurch/6d4622fdea4a6233bcc866e483063e51 to your computer and use it in GitHub Desktop.
Array Chonk (Array chunking)
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
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