Why si there an infinite loop in my code?

Genuinely don’t understand - what is line 8 doing that is so naughty?

  1. Try walking a rubber ducky through your logic. You may be surprised by what happens when your first two letters are “AT” or “GC”.

  2. Please copy and paste your code instead of taking a screenshot on future posts.

1 Like

Just looking at your code quickly, I see a few problems.

You are making an adjustment to an array that is also the array.length you are using for your for loop. Do you see the problem here? It gets one cell larger each iteration so the for loop will never get to the end.

The other problem is that your return needs to be an array of two cell arrays.

You created a dummy array, arr. That could solve both of your problems. Instead of manipulating sec, push the data onto arr. But make sure it an array of two elements.

And I’n not sure about your logic:

if (sec[i] == ‘A’ && sec[i+1]!='T’) {

Why are you checking what the next element is? Maybe this is left over from when you were splicing in elements. But the logic should be based on just one element in the sec array.

or to help us help you, can you share the logic for your solution?

above comments are right on the money about what’s going on here.

create a new array with your answer based off the old array instead of trying to modify the old array and you’l lhave an easier time.