I've been working on the freecodecamp Bonfire: Chunky Monkey problem and I'm almost there with the solution. However, I'm stuck on why the output is [['a', 'b']], instead of [['a', 'b'], ['c', 'd']]. Can anyone help me figure out what's wrong with my code?
function chunk(arr, size) {
var array = [];
var tmp = [];
for(var i = 0; i < Math.floor(arr.length/size); i++) {
for(var j = 0; j < size; j++) {
tmp.push(arr[j]);
}
array.push(tmp);
tmp = [];
arr.splice(0,size);
}
return array;
}
chunk(['a', 'b', 'c', 'd'], 2);