Skip to content

Instantly share code, notes, and snippets.

@zmnv
Created December 29, 2018 16:46
Show Gist options
  • Save zmnv/2c1b04f0918a88f80f7f19e17e9ad0c0 to your computer and use it in GitHub Desktop.
Save zmnv/2c1b04f0918a88f80f7f19e17e9ad0c0 to your computer and use it in GitHub Desktop.
Group array elemens by elements size
function groupArray(array = [], size = 10) {
const res = array.reduce((p, c) => {
if (p[p.length - 1].length == size) {
p.push([]);
}
p[p.length - 1].push(c);
return p;
}, [[]]);
return res;
}
module.exports = groupArray;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment