Tell us what’s happening:
Thank you for your help.
With the current code im failing the first test of (hello, hey) should return false but i keep getting true.
However if i use result to assign true or false depending on the letter being checked in loop and then return result after the ‘for loop’ like below i pass the first one but fail three others that should be false but come back true
function mutation(arr) {
let checkAgainst = arr[0].toLowerCase().split('');
let checkFor = arr[1].toLowerCase();
let letters = checkFor.split('');
let result;
for(let idx = 0; idx < letters.length; idx ++){
let letter = letters[idx];
console.log(letter)
if(checkAgainst.indexOf(letter) !== -1){
result = true;
} else{
result = false;
}
}
return result;
}
console.log(mutation(["hello", "hey"])); // false
console.log(mutation(["floor", "for"])); // true
console.log(mutation(["hello", "neo"])); // false
console.log(mutation(["voodoo", "no"])); // false
Your code so far
function mutation(arr) {
let checkAgainst = arr[0].toLowerCase().split('');
let checkFor = arr[1].toLowerCase();
let letters = checkFor.split('');
let result;
for(let idx = 0; idx < letters.length; idx ++){
let letter = letters[idx];
console.log(letter)
if(checkAgainst.indexOf(letter) !== -1){
return true;
} else{
return false;
}
}
}
console.log(mutation(["hello", "hey"]));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36
.
Challenge: Mutations
Link to the challenge: