[SOLVED] Chunky Monkey disappearing value

EDIT: I’ve figured out what’s going on.

Tell us what’s happening:

My code below is not working as planned. For some reason unknown to me, my function is skipping every other element in the returned array. For example, given the parameters below, the function will return: [[1, 2], [4, 5], [7, 8]], skipping the values 3, 6, and 9.

Dear friends around the bonfire, can somebody please show me the light, thank you.

Your code so far

function chunkArrayInGroups(arr, size) {
// Break it up.
var temp = [];
var result = [];

for (var i = 0; i < arr.length; i++) {
if (temp.length !== size) {
temp.push(arr[i]);
} else {
result.push(temp);
temp = [];
}

}
if (temp.length > 0) {
result.push(temp);
}

return result;
}

chunkArrayInGroups([1, 2, 3, 4, 5, 6, 7, 8, 9], 2);
// this will return : [[1, 2], [4, 5], [7, 8]]
Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36.