Guest User

Untitled

a guest
Aug 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. // chunk array reduces the array to a set of chunks of size n
  2. const chunkArray = (a = [], n = 2) =>
  3. a.reduce((acc, el, idx) => {
  4. const chunk = Math.floor(idx / n);
  5. if (!Array.isArray(acc[chunk])) acc[chunk] = [];
  6. acc[chunk].push(el);
  7. return acc;
  8. }, []);
Add Comment
Please, Sign In to add comment