Implement the Chunky Monkey Algorithm - Implement the Chunky Monkey Algorithm

Tell us what’s happening:

Hi everyone, i pass this lab with this code. I saw others code and i like their code, which is shorter than mine. (I don’t even think about .slice() )

“fish_99” pass the lab and ask some comments or recommendation on his code. I want to do the same with my code.

Maybe my result is right but my method is wrong.

Your code so far

function chunkArrayInGroups (arr, num) {
let groups = [];
let arrayOfArray = [];
let i = 0;

  for (const n in arr) {

    if (groups.length < num) {
      groups.push(arr[n]);
      i++;

    } else if (groups.length = num) {
      arrayOfArray.push(groups);
      groups = [];
      groups.push(arr[n]);
      i++;
    }
  }
  
  if (i = arr.length) {
    arrayOfArray.push(groups);
  }

return arrayOfArray;
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Implement the Chunky Monkey Algorithm - Implement the Chunky Monkey Algorithm

Why do you say your method is wrong? Barring any unexpected edge cases that are missed by tests, your method is literally correct. Having working and correct code is a perfect time to take another look to try to improve it.

What would you say was the hardest? What was the easiest? Any clear places that you’d want to improve?

1 Like

You are using assignment operators rather than equality operators in these conditionals.

1 Like

thank you i should use ( === or == )