Please explain me why :(

Hello guys! I am learning and am at Basic Algorithm Scripting: Mutations. I came up with an apparently solution. It works with everything else, but with this exemple don’t.

function mutation(arr) {
     let all = arr[1].toLowerCase();
     let some = arr[0].toLowerCase();
     for (let i = 0; i < all.length; i++) {
       if (some.indexOf(all[i]) != -1) {
         console.log (some.indexOf(all[2]))
         return true;
       } return false;
 mutation(["hello", "hey"]);

I don’t understand why in console it says that indexOf(all[2]) it’s -1, but still the answer is true even it’s false.

Hey @gheorgheburduja,
Just a quick tip, next time if you need a help from a challenge, you can use the Get Help button on the sidebar. It lets everyone be able to see the challenge, and your code in a more formatted way, so we can help you easier

1 Like

With the way you have written your logic, you will only be checking to see if some has the the first character of the all array. If it does, then you will return true. If it does not, it will return false.

The reason your function appears to pass most of the test is pure coincidence, based on the fact that most of the tests expect a value of true to be returned. You just got lucky on most of the tests.

Rethink your logic and you will be fine.