Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // chunk array reduces the array to a set of chunks of size n
- const chunkArray = (a = [], n = 2) =>
- a.reduce((acc, el, idx) => {
- const chunk = Math.floor(idx / n);
- if (!Array.isArray(acc[chunk])) acc[chunk] = [];
- acc[chunk].push(el);
- return acc;
- }, []);
Add Comment
Please, Sign In to add comment