Tell us what’s happening:
Can someone explain why the output of the code is always false? Its supposed to return true whenever all of the characters in the second word are present in the first word, regardless of case. I converted both strings into an array of individual uppercase letters and tried to use .indexOf to check if the character is present or not.
Your code so far
function mutation(arr) {
arr[0] = arr[0].toUpperCase();
arr[1] = arr[1].toUpperCase();
arr[0] = arr[0].split('')
arr[1] = arr[1].split('')
for(let i = 0; i< arr[1].length;i++ ){
if(arr[0].indexOf(arr[1][i] == -1)){
return false
} else return true
}
}
mutation(["hello", "Hello"]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
.
Challenge: Mutations
Link to the challenge: