Chunk a List, Keeping the Item Type
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write chunk(items, size): split items into lists of size items each, in order, with a shorter last list if they don't divide evenly. An empty list gives no chunks, and a size that isn't a whole number of at least 1 throws. Type it so chunking a string[] gives string[][], and so passing a size that isn't a number (the string "2", say) is a type error.
Your code must pass
- Splits into chunks of size, the last one shorter
- Returns no chunks for an empty list
- Throws for a size below 1
- Has no type errors
- Chunks keep the items' type
- Rejects a size that isn't a number