Created
March 5, 2020 08:03
-
-
Save cedrickvstheworld/98ed29b17dd97d2acf4e6836f655a387 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
let testArr = [...Array(23).keys()] | |
function chunk(arr, size) { | |
let chunkie = [] | |
let newConstruct = [] | |
for (let i in arr) { | |
if (chunkie.length < size - 1) { | |
chunkie.push(arr[i]) | |
if (arr.length === parseInt(i) + 1) { | |
newConstruct.push(chunkie) | |
} | |
} | |
else { | |
chunkie.push(arr[i]) | |
newConstruct.push(chunkie) | |
chunkie = [] | |
} | |
} | |
return newConstruct | |
} | |
console.log(chunk(testArr, 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment