Last active
January 6, 2021 02:15
-
-
Save robertz/695194450223ea85d26a6fac0cde68f0 to your computer and use it in GitHub Desktop.
given an array, return an array of arrays with {{chunkSize}} elements
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
component { | |
// given an array, return an array of arrays with {{chunkSize}} elements | |
function chunk (required array input, required numeric chunkSize) { | |
var output[1] = []; | |
var idx = 1; | |
input.each((item, index) => { | |
output[idx].append(item); | |
if(index % chunkSize == 0 && index < input.len()) output[++idx] = []; | |
}) | |
return output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment