What Went Wrong?: Mutations

Why doesn’t this work?

Your code so far


function mutation(arr) {
  var testStr = arr[0].toLowerCase().split("");
  var testRegex = arr[1].toLowerCase().split("");
  
  for(var i = 0; i < testRegex.length; i++){
    if(testStr.indexOf(testRegex[i]) == true){
      return true;
    } else return false;
  }
  
}

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

Your browser information:

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

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

Hi SharonNg88,

This doesn’t work because when first true occurs function return true and exit, same for false, and you doesn’t test all the letters of array(string) elements.

Hint: indexOf returns -1 when there is no element in array or letter in string.