I\'m using this function to create chunks of an array:
function chunkArray(myArray, chunk_size) { let results = []; while (myArray.length) {
I'd do something like this:
function chunkArray(src, chunkSize ) { const chunks = Math.ceil( src.length / chunkSize ); const chunked = []; for (let i = 0; i < src.length; ++i) { const c = i % chunks; const x = chunked[c] || (chunked[c]=[]); x[ x.length ] = src[i]; } return chunked; }