Mutations: the first case doesn't pass the tests

Mutations: the first case doesn't pass the tests
0

#1

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:


#2

Your code gets lucky in passing the other tests. Your solution only goes through one iteration of the for loop, because you are using a return statement in both the if and else blocks of code. Once a return statement is executed, the corresponding value is returned and the function is exited regardless if it was not finished iterating through the entire loop. You just need to tweak your code logic a little.


#3

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”.


#4

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.


#5

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!