function chunkArrayInGroups(arr, size) {
// Break it up.
var temp = [];
var divisions = arr.length / size;
while(arr.length>0){
var temp2 = [];
for(var i=0; i<size; i++){
if(arr.length<=0){
break;
}
temp2.push(arr.shift());
}
temp.push(temp2);
}
return temp;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
No comments:
Post a Comment