Mutations - What's wrong with my code?

I’m trying to pass this way point but I can’t get my code to pass. ‘gabriel’ and ‘bee’ return true but ‘gabriel’ and ‘gabriel’ return false.


function mutation(arr) {
one = arr.slice(0,1).toString().toLowerCase();
two = arr.slice(1,2).toString().toLowerCase();
z = 0
for (x = 0; x < two.length; x++){
  if (one.indexOf(two[x]) > 0) {
    z++;
  }
}


if (z === two.length){
  return true;
} else {
  return false;
}
  
}
  
mutation(['gabriel','bee'])

0 is also a valid array index, but you’re not taking that into account.


On another note, using slice is a bit of an overkill. You can access the strings just by using bracket notation.

It’s also a good habit to use the let keyword when declaring variables.

Thanks for your help, I updated my code and passed to the next waypoint.