1let input = [1,2,3,4,5,6,7,8,9];
2let chunked = []
3let size = 2;
4
5for (let i = 0; i < input.length; i += size) {
6 chunked.push(input.slice(i, i + size))
7}
8console.log(chunked)
1function __chunk(array, size) {
2 let chunkArray = [];
3 return function _chunk(chunk = array) {
4 if (chunk.length < size) {
5 return chunkArray.push(chunk) && chunkArray;
6 }
7 return chunkArray.push(chunk.slice(0, size)) && _chunk(chunk.slice(size));
8 };
9}