Array2 is not iterable

There’s an error when I’m pressing the attempt button:
TypeError: array2 is not iterable
However, when I press the test button, it works fine. Why is that?

my code:

function comp(array1, array2) {
  let newSecondArr = [];
  for (let elements of array2) {
    newSecondArr.push(Math.sqrt(elements))
  }
  return array1.sort((a, b) => a - b).join(',')
    === newSecondArr.sort((a, b) => a - b).join(',')
}

Link to the challenge: https://www.codewars.com/kata/550498447451fbbd7600041c/train/javascript

Hello there.

Do you have a question?

If so, please edit your post to include it.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

1 Like

Thank you for the reply. I edited my post :slight_smile:

check the remarks in the kata description - are you always given arrays?

1 Like

It worked!

I added an if statement: if (array1 !== null && array2 !== null) and I changed the for…of loop to this: for (let i = 0; i < array2.length; i++)

Thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.