Mutations: how to fix the letter cases

I have figured out how to compare the letters in each string of the array but I keep getting issues which I believe are caused when testing strings that contain the same letter but different letter cases. If someone could help me I would be very grateful

function mutation(arr) {
for (var i = 0; i < arr.length; i++){

for (var j = 0; j < arr[i].length; j++){

if( arr[0].indexOf(arr[1].charAt(j)) == -1){
  return false;} 
else{
  return true;
  }
  
}

}
}

mutation([“hello”, “hey”]);

Hello Tobel158,

Does the array always only contain two strings?

If you do not care about the case you can convert both strings (or characters) to upper or lower case using the toUpperCase or toLowerCase functions.

1 Like

Thanks midenfors, I used the toLowerCase function and i got the following. It works well but might need some cleaning up.

function mutation(arr) {
var newArr= [];
newArr.push(arr[0].toLowerCase());
newArr.push(arr[1].toLowerCase());
for (var i = 0; i<arr.length;i++){

for (var j=0; j<arr[i].length;j++){
 if( newArr[0].indexOf(newArr[1].charAt(j))==-1){
   return false;
 }
     
}

}return true;
}

mutation([“hello”, “hey”]);

Glad I could be of help. Clean code comes with time, just keep at it.

Just a note about how to display code in this forum; if you have a block of code as the one above, put three backticks above and bellow it. Read more here.