Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function chunk(array, size) {
- if (!array) return [];
- const firstChunk = array.slice(0, size); // create the first chunk of the given array
- if (!firstChunk.length) {
- return array; // this is the base case to terminal the recursive
- }
- return [firstChunk].concat(chunk(array.slice(size, array.length), size));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement