Mutations - first problem

Mutations - first problem
0.0 0

#1

Tell us what’s happening:
The only thing that is not passing is the very first one: mutation([“hello”, “hey”]) should return false.

Your code so far


function mutation(arr) {
    let arr1 = arr[0].toLowerCase();
    let arr2 = arr[1].toLowerCase();

    for(let i = 0; i < arr2.length; i++) {
      if(arr1.indexOf(arr2[i]) < 0) {
        return false;
      } 
      return true;
    }

}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations


#2

You just got lucky on the other tests, because your for loop only makes one iteration before returning a value of true or false. Once a return statement is executed, the function immediately exits.

Hint: Think about when you should actually return true.


#3

I got it! Thank you!