Created
September 18, 2019 12:08
-
-
Save ninadvadujkar/3d8cd2325667f573ea83954aec919101 to your computer and use it in GitHub Desktop.
This file contains 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 explode(array, chunkSize) { | |
if (chunkSize === 0) return []; | |
const explodedArr = []; | |
let innerArr = []; | |
for (let i = 0; i < array.length; i++) { | |
innerArr.push(array[i]); | |
if ( (i + 1) % chunkSize === 0) { | |
explodedArr.push(innerArr); | |
innerArr = []; | |
} | |
} | |
if (innerArr.length !== 0) { | |
explodedArr.push(innerArr); | |
} | |
return explodedArr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment