a guest Apr 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand