1function chunk(array, size) {
2 const result = [];
3
4 for (let i = 0; i < array.length; i += size) {
5 result.push(array.slice(i, i + size));
6 }
7
8 return result;
9}
10
11// Usage example
12const numbers = [1, 2, 3, 4, 5, 6, 7, 8];
13console.log(chunk(numbers, 3));
14// Output: [[1, 2, 3], [4, 5, 6], [7, 8]]Organize your team's code snippets with Snippetly. Share knowledge and boost productivity across your organization.