# Please give a look! Noob utterly baffled by the behavior in this beginner algorithm 'Mutations'

Tell us what’s happening:
First I’d like to thank anyone taking the time and effort to parse through this mess of code. I am struggling to pass two of the tests in this algorithm challenge. The two failing tests that should pass are mutation([“Mary”, “Army”]) and mutation([“Mary”, “Aarmy”]). I cannot for the life of me understand why. Debugging as best I can tells me that my if statement is returning false on the third loop, at which point my indicator variable is [0,0,‘m’,‘r’,‘y’] and the letterToMatch variable is ‘m’. I’m really struggling to understand, but somehow:

arr[0].indexOf(letterToMatch)<0

or as I interpret:

[‘a’,‘a’,‘m’,‘r’,‘y’].indexOf(‘m’)

is returning a false negative when it should give an index value of 2?

``````function mutation(arr) {
var firstWordSorted = arr[0].toLowerCase().split('').sort();
var secondWordSorted = arr[1].toLowerCase().split('').sort();
var indicator = secondWordSorted;

for (i=0; i<secondWordSorted.length; i++) {
var letterToMatch = secondWordSorted[i];
console.log('ltm', letterToMatch, i, indicator);
if (arr[0].indexOf(letterToMatch)<0) {
console.log('fail');
return false;
} else {
indicator[indicator.indexOf(letterToMatch)] = 0;

}
if (indicator.reduce(function(a,b) {return a+b;}, 0) == 0) {
console.log('pass');
return true;}
}
}

mutation(["Mary", "Aarmy"]);```