Split an Array into Chunks
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write chunk(items, size), where size is a whole number of at least 1: return a new array of arrays, each holding the next size items in order, except the last, which holds whatever is left over. Every chunk is a new array, even when it holds all the items. An empty array gives an empty array, and items itself is never changed.
Your code must pass
- Splits the items into groups of size
- Puts the leftover items in a shorter last group
- Returns an empty array for no items
- Makes new arrays and leaves the input alone