This code passes all but the ‘hello’, ‘hey’ challenge. It looks like it’s running the first letter or two. I can fix it but I’m having a hard time figuring out how to see what it’s doing.
function mutation(arr) {
var words = arr;
var firstString = words[0].toString().toLowerCase();
var secondString = words[1].toString().toLowerCase();
for (var i = 0; i <= secondString.length; i++) {
if (firstString.indexOf(secondString[i]) !== -1) {
return true;
function mutation(arr) {
var words = arr;
var firstWord = words[0].toString().toLowerCase();
var secondWord = words[1].toString().toLowerCase();
var tester = secondWord.length;
for (var i = 0; i < secondWord.length; i++) {
if (firstWord.indexOf(secondWord[i]) !== -1) {
tester–;
}
}
[Solved]
I have the same problem and it doesn’t make sense to me how every other test passes.
function mutation(arr) {
control = arr[0].toLowerCase();
test = arr[1].toLowerCase().split('');
for (i = 0; i < test.length; i++){
if(control.indexOf(test[i]) < 0){
return false;
}
return true ;
}
}
mutation(["hello", "hey"]);
I don’t understand how your countdown var tester = secondWord.length; solves the problem.
EDIT: Ok wow I got it, I just needed to put the return true outside of the scope of the for loop.
function mutation(arr) {
var args0=arr[0].toLowerCase();
var args1=arr[1].toLowerCase();
for(var i=0;i<args1.length;i++)
{
if(args0.indexOf(args1[i])===-1){return false;}
}
if (i===args1.length) return true;
Hey,
I had the same exact problem. Why should we put the “return true” statement oustide of the loop function? Shouldn’t it be inside as an “else” statement?
It seems as if we do it as we did, it loops only the first word of the second word, and returns therefore true for all the challenges, apart from the first one, where the missing letter is at the end (“hey”).
Mysterious! Could someone explain this?