Here is my solution to the Chunky monkey problem.

function chunkArrayInGroups(arr, size) {

var twoDArray=[];

var arrayLength=arr.length;

//this variable calculates number of groupings less the

//left over that will end up in 2D array.

var numOfGroupings=Math.floor(arrayLength/size);

//size of left over end of array

var remainder=arrayLength%size;

//if there is a left over remainder at the end of the array

if(remainder > 0){

twoDArray.unshift(arr.splice(-remainder,remainder));

}

for(var i=0;i<numOfGroupings;i++){

twoDArray.unshift(arr.splice(-size,size));

}

return twoDArray;

}

This code works but I am interested in how to eliminate the need for dealing with the left over

end of the array. This way the program would be simplified to a for loop with one command. Any help/ideas would be appreciated. Thank you.