Skip to content

Instantly share code, notes, and snippets.

@dmidlo
Created November 23, 2015 04:49
Show Gist options
  • Save dmidlo/a2843b388a23411bde37 to your computer and use it in GitHub Desktop.
Save dmidlo/a2843b388a23411bde37 to your computer and use it in GitHub Desktop.
function chunkArray(arr, size) {
// creates a matrix of N elements from a single array
var resultArray = [];
for (var i = 0; i < arr.length; i += size) {
resultArray.push(arr.slice(i, i + size));
}
return (resultArray);
}
chunkArray(["a", "b", "c", "d", "e"], 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment