Implement a function chunk that splits an array into groups of a specified size. If the array can't be split evenly, the final chunk should contain the remaining elements.
Use the following example to understand how the chunk function should work:
function chunk(array, size) {
// Your implementation here
}
const arr = [1, 2, 3, 4, 5, 6, 7];
const result = chunk(arr, 3);
console.log(result);
// Output: [[1, 2, 3], [4, 5, 6], [7]]
⚙️
Booting up the editor...
Please wait while we load the editor.
⚙️
Loading Preview...