function mutation(arr) {
return arr;
}
mutation(["hello", "hey"]);
- For example,
["hello", "Hello"]
, should returntrue
because all of the letters in the second string are present in the first, ignoring case. - The arguments
["hello", "hey"]
should returnfalse
because the string hello does not contain a y.
Hint:
- If everything is lowercase it will be easier to compare.
- Our strings might be easier to work with if they were arrays of characters.
A loop might help. Use
indexOf()
to check if the letter of the second word is on the first.Answer:
function mutation(arr) {
let firstWord = arr[0].toLowerCase();
let secondWord = arr[1].toLowerCase();
for (let i = 0; i < secondWord.length; i++) {
let letters = secondWord[i];
if (firstWord.indexOf(letters) === -1) return false;
}
return true;
}
mutation(["hello", "hey"]); // will display false
Top comments (0)