function mutation(arr) {
for(var i = 0; i < arr.length; i ++) {
arr[i] = arr[i].toLowerCase().split('');
if (arr[0].indexOf(arr[0]) == arr[0].indexOf(arr[1])) {
return true;
} else {
return false;
}
}
return arr;
}
mutation(["Mary", "Army"]);
any idea on how can i compare these two word s/ or what am i doing wrong? thank you
Im failing every tests that are supposed to show “false”
Thank you for your reply. My main reason for loop was that i wanted to lowercase all words as just using .toLowerCase(). wasnt working for me .
I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.
function mutation(arr) {
var lettersToCheck = arr[0].toLowerCase();
var lettersToFind = arr[1].toLowerCase();
for (var i = 0; i < lettersToFind.length; i ++) {
if (lettersToCheck.indexOf(lettersToFind[i]) >= 0) {
return true;
} else {
return false;
}
}
return arr;
}
mutation(["hello", "hey"]);
it doesnt return false in case [“hello”, “hey”] but other variants passes … any hint about what im doing wrong ?
jenovs
10
Your code checks only the first letter and after that it returns.
You’re trying to see if each index of arr[1] matches an index of arr[0]. Hint: nested loops, one for each item.
I like your idea of lower-casing both items. I used RegExp to ignore case in my solution.