Skip to content

Instantly share code, notes, and snippets.

@AviTapp
Last active December 26, 2017 19:12
Show Gist options
  • Save AviTapp/2de37814587fe6d61eb39648912daae7 to your computer and use it in GitHub Desktop.
Save AviTapp/2de37814587fe6d61eb39648912daae7 to your computer and use it in GitHub Desktop.
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
function chunkArrayInGroups(r, n) {
var u = [],
c = 0,
e = n,
h = [];
for (i = 0; i < r.length;) u = r.slice(c, e), h.push(u), c += n, e += n, i += n;
return h
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment