Mutations: the first case doesn't pass the tests

Tell us what’s happening:
Here is the screenshot of my problem:


I have no idea why the first case doesn’t pass the tests.
Maybe you know the issue?

Your code so far

    
    var a = arr[0].toLowerCase();
    var b = arr[1].toLowerCase().split("");
    

    for (i=0; i<b.length; i++) {    
      
    if(a.indexOf(b[i])!=-1) 
      
    return true;      
      
    else return false;}
}

mutation(["hello", "hey"]);

Your browser information:

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

Link to the challenge:
https://www.freecodecamp.org/challenges/mutations

Thank You for your help but I still can’t get things clear for myself.

Why this code passes the tests:


And this code doesn’t pass the tests:

As it seems to me, we simply change the “POSITIVE” logic to “NEGATIVE”.

The first one works correctly because during each iteration of the for loop, you are checking if current letter of the b array is NOT in a. When a false condition exists, then it correctly returns false. Once it has iterating through the entire array a, then that means all the letters were found, so true is returned.

The second one is not close at all, because during each iteration of the for loop, you are checking if current letter of the b array is NO in a. When a false condition exists, then you are returning true which is not at all what you want. Also, with the second one, if the entire is iterated, which means all the letters were found, your solution returns false.

1 Like

I see You understand the problem.
Maybe I shall understand the issue later.
It’s still some unclear to me but I know the right way.
Thank You for Your help!