Skip to content

Files

Latest commit

 

History

History
21 lines (13 loc) · 1.69 KB

File metadata and controls

21 lines (13 loc) · 1.69 KB

Chunk easy #javascript

by Pawan Kumar @jsartisan

Take the Challenge

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]]

Back Share your Solutions Check out Solutions