Problem
I wrote a function which takes an array and returns true if the string in the first element of the array contains all of the letters of the string in the second element of the array. The function worked as intended till ["hello", "hey"] given as an argument. It should return -1 since the first element of the array doesn't contain "y". How do I solve this problem?
Script
function mutation(arr) {
let lower = arr[0].toLowerCase();
let lower1 = arr[1].toLowerCase();
let count = 0;
for (let i = 0; i < lower.length; i++) {
if (lower.indexOf(lower1[i]) == -1) {
return false;
}
else {
count += 1;
}
if (count > 0) {
if (count.legth == lower.legth) {
return true;
}
else {
return false;
}
}
}
}
Result
mutation(["hello", "hey"]);
true //should return false
arr = ["hello", "hey"];
arr[0].indexOf(arr[1][2]);
-1