Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. function chunk(array, size) {
  2. if (!array) return [];
  3. const firstChunk = array.slice(0, size); // create the first chunk of the given array
  4. if (!firstChunk.length) {
  5. return array; // this is the base case to terminal the recursive
  6. }
  7. return [firstChunk].concat(chunk(array.slice(size, array.length), size));
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement