Hello all!
I have a quick question: here’s the code that I wrote to solve this exercise:
function mutation(arr) {
for(var i = 0; i < arr[1].length; i++){
console.log(arr[1][i])
if(arr[0].toLowerCase().includes(arr[1][i].toLowerCase())){
} else {
return false;
}
}
return true;
}
mutation(["hello", "hey"]);
I originally had it like this:
function mutation(arr) {
for(var i = 0; i < arr[1].length; i++){
console.log(arr[1][i])
if(arr[0].toLowerCase().includes(arr[1][i].toLowerCase())){
return true;
} else {
return false;
}
}
}
mutation(["hello", "hey"]);
When I had return true as part of the first code statement in the if conditional, the first test case in the exercise (['hello', 'hey']) wasn’t passing. Yet, when I moved it to outside of the for loop, the test case passed .
Why did moving return true to the outside of the for loop make it pass?
If I’m being super unclear, please let me know and I’ll elaborate further!
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36.
Challenge: Mutations
Link to the challenge: