Mutations - issue with for loop

Mutations - issue with for loop
0.0 0

#1

Tell us what’s happening:
My problem is that the array works for all values that are true but it doesnt return the false, I checked the solution after i wrote this and it is almost exactly the same, the only difference is that they store the array values in 2 different containers. What’s wrong with my code?

Your code so far

function mutation(arr) {
   //  My solution is below, i'm not sure why it won't work
//Lower case everything  
arr.map(function(x){return x.toLowerCase();});
  
//Iterate through the array[1] and check if it exists in arr[0] if it does, return true, else return false
  for (var j = 0; j < arr[1].length; j++){
    if (arr[0].indexOf(arr[1][j]) != -1)
      return true;
  }  
  return false;
}

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

Link to the challenge:


#2

i think you may have mismatched a bracket after the if statement and also when i tested i found your lowercase map wasn’t working. Also your design would return true if one letter is in the other word rather than checking all the characters. Here’s my solution based on your code:

function mutation(arr) {
 //  My solution is below, i'm not sure why it won't work
//Lower case everything  
arr[0] = arr[0].toLowerCase();
arr[1] = arr[1].toLowerCase();
//Iterate through the array[1] and check if it exists in arr[0] if it does, return true, else return false 
for (var j = 0; j < arr[1].length; j++){
    if (arr[0].indexOf(arr[1][j]) == -1){
      return false;
  
      }
}
return true;
}

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