Help for "Chunky Monkey"

Help for "Chunky Monkey"
0

#1

I tried to solve the problem, but I do not find why this solution gives wrong answer. I add window.alert() for debugging, Please help to find error.

 function chunkArrayInGroups(arr, size) {
 var newAra=[];
 var araSize=Math.ceil(arr.length/size);
 for(var i=0;i<araSize;i++)
{
newAra[i]=[];
 }
var index=0;
for(i=0;i<arr.length;)
 {
  for(j=0;j<size;j++)
    {
     if(i>=arr.length)
     break;
 //     window.alert(arr[i]);
      newAra[index].push(arr[i]);
      i++;
    }
  index++;
}
for(i=0;i<newAra.length;i++)
window.alert(newAra[i]);
return newAra;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)
//chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)
//chunkArrayInGroups([0,1,2,3,4], 2);

#2

Your debugging code is what causes the error! Try removing the for-loop with the alert in it.

I use console.log for debugging, usually on repl.it.