I managed to solve the problem, but only after removing the else condition in my if loop. All of the test cases passed except when [“hello”, “hey”] was passed into the function.
Why does this work:
function mutation(arr) {
var matchString = arr[0].toLowerCase();
var refString = arr[1].toLowerCase();
for (var i = 0; i < refString.length; i++){
if (matchString.indexOf(refString[i]) === -1){
return false;
}
}
return true;
}
mutation(["hello", "hey"]);
But not this:
function mutation(arr) {
var matchString = arr[0].toLowerCase();
var refString = arr[1].toLowerCase();
for (var i = 0; i < refString.length; i++){
if (matchString.indexOf(refString[i]) === -1){
return false;
} else {
return true;
}
}
}
mutation(["hello", "hey"]);
I’m so confused as to what is semantically different between these two functions. Thanks for your input!
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0
.
Link to the challenge:
https://www.freecodecamp.org/challenges/mutations