Basic Algorithm Scripting: Chunky Monkey (Console.log shows test is passed but FCC won't accept it)

Can someone give me a hand with what the issue is? I’ve spent like two hours already…
It’s exactly with the input in this example that I’m getting the issue.

var result = [];
function chunkArrayInGroups(arr, size) {
  if(size < arr.length){
    let siRe = (arr.length%size!=0 ? 1 + parseInt(arr.length/size)                              :arr.length/size);
    console.log('Numbers of arrays within the result: '+siRe);
    for (let i = 0; i < siRe; i++){
      if(arr[i] !== ''){
        result[i] = (arr.splice(0,size));
        console.log('Array #'+ (i + 1) + ': '+ result[i]);
    return arr;
  return result;

console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4));

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.


var myGlobal = [1];
function returnGlobal(arg) {
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  return myLocal;
} // reliable - always returns an array of length 2

Also, in the future when you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like

Very clear response. Thanks a lot!