cf.completefrontend

Write the codeEasy

Write chunk(array, size) that splits an array into groups of size elements.

The last group holds whatever is left over. Don't change the input array. Throw a RangeError if size isn't a positive integer.

Write this
function chunk(array, size) {
  // your code
}
 
// chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
// chunk([1, 2, 3], 5);       // [[1, 2, 3]]
// chunk([], 3);              // []

Solve it in the editor, with tests

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…