Last active
December 14, 2021 18:58
-
-
Save scarletquasar/217734a86916d1cc20825d77defd7f40 to your computer and use it in GitHub Desktop.
Chunk array with dynamic group length
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
let res = []; | |
let base = [1, 2, 3, 4]; | |
let groupQuantity = 2; | |
for(let i = 0; i < base.length; i += groupQuantity) { | |
let even = []; | |
for(let gq = 0; gq < groupQuantity; gq++) { | |
base[i + gq] ? even.push(base[i + gq]) : {}; | |
} | |
res.push(even); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment