Tell us what’s happening:
The last subchallenge which says mutation([“voodoo”, “no”]) is returning true. The o is getting matched twice. I am still not able to figure out where indexOf() comes handy here. It is given among the ‘helpful links’.
Your code so far
function mutation(arr) {
var str1=arr[0].toLowerCase();
var str2=arr[1].toLowerCase();
var arr1=str1.split('');
var arr2=str2.split('');
var match=0;
for(var i=0;i<arr1.length;i++)
{
for(var j=0;j<arr2.length;j++)
{
if(arr2[j]===arr1[i])
match++;
if(match===arr2.length)
break;
}
}
if(match===arr2.length)
return true;
else
return false;
}
mutation(["voodoo", "no"]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
.
Link to the challenge: