Skip to content

Instantly share code, notes, and snippets.

@ccnixon
Created February 17, 2016 18:22
Show Gist options
  • Save ccnixon/87a059f510bcddac0f42 to your computer and use it in GitHub Desktop.
Save ccnixon/87a059f510bcddac0f42 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 chunk(arr, size) {
var results = [];
while(arr.length){
results.push(arr.splice(0,size));
}
return results;
}
chunk(["a", "b", "c", "d"], 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment