Help for Chunky Monkey

Help for Chunky Monkey
0

#1

I tried using this code, and the answer that gets returned is appropriate, but the Code Check returns all negative. Please help me find the problem.

var fArr = [];
function chunkArrayInGroups(arr, size) {
  var j = 0;
  for (var i = 0; i< (arr.length/size); i++) {
  var tArr = arr.slice(j,j+size);
  fArr.push(tArr);
  j = j+ size;
  }
  return fArr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4);

#2

I modified your solution two ways.

First, I moved your globally declared fArr array variable inside your function. You will have problems with the subsequent tests after the first if not.

Second, you will notice I put a console.log right before the return, to show you that tArr has the missing value. Now that you no where it is, see if you can figure out how to incorporate it before making the final return statement.

function chunkArrayInGroups(arr, size) {
  var fArr = [];
  var j = 0;
  for (var i = 0; i< (arr.length/size); i++) {
    var tArr = arr.slice(j,j+size);
    fArr.push(tArr);
    j = j+ size;
  }
  console.log(tArr);
  return fArr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4);