Hi all,
I’m fairly new to fcc, as I’ve only been working on the front end development cert for a couple of weeks now. I’ve taken a look at the code provided as the solution for this challenge, and its really similar to the one that i wrote here, except my code returns a true for [“hello”, “hey”] instead of a false. The solution given in the hint section says removing the else statement, and moving the “return true;” outside of the for loop will fix the issue, and it does, but I don’t understand why. Does anyone know what the difference in the logic is?
Your code so far
function mutation(arr) {
var newArr1= arr[0].toLowerCase();
var newArr2 = arr[1].toLowerCase();
for(var i = 0; i<newArr2.length;i++){
if( newArr1.indexOf(newArr2[i]) === -1 ){
return false;
} else {
return true;
}
}
}
mutation(["hello", "hey"]);
Link to the challenge: