Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created March 17, 2017 05:00
Show Gist options
  • Select an option

  • Save lachlan-eagling/1064f98f392650d5ec964372b369be10 to your computer and use it in GitHub Desktop.

Select an option

Save lachlan-eagling/1064f98f392650d5ec964372b369be10 to your computer and use it in GitHub Desktop.
function chunkArrayInGroups(arr, size) {
var tempArr = [];
var innerTempArr = [];
for(var i = 0; i < arr.length; i++){
if(innerTempArr.length < size){
innerTempArr.push(arr[i]);
} else{
tempArr.push(innerTempArr);
innerTempArr = [];
innerTempArr.push(arr[i]);
}
}
tempArr.push(innerTempArr);
arr = tempArr;
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment