Tell us what’s happening:
I’m not sure why my code isnt looping all the way through the complete length of the string. And why all but one keeps failing
Your code so far
function mutation(arr) {
for (i=0; i < arr[1].length; i++) {
return (arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase()) >= 0);
}
}
mutation(["hello", "hey"]);
//I figured out a solution but I still would like and explanation as to why this wont work:
for (i=0; i < arr[1].length; i++) {
if (arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase()) >= 0){
return true;
}
}
return false;
}
//but this will:
function mutation(arr) {
for (i=0; i < arr[1].length; i++) {
if (arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase()) === -1){
return false;
}
}
return true;
}
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/mutations