How do i solve mutations challenge

Hi guys,what is wrong with my code??

  **Your code so far**

function mutation(arr) {
 arr.sort(function(a, b) {
  return a.length - b.length;
});

for (var i = 0, len = arr[0].length; i < len; i++) {
  if (arr[1].toLowerCase().indexOf(arr[0][i].toLowerCase()) < 0) {
    return false;
  }
}
return true;
}

console.log(mutation(["hello", "hey"]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: Mutations

Link to the challenge:

Hello @columbuschidozie1 ,

Your code only passes all the tests except one because the second word in all them is shorter than or as long as the first (excepting ["Mary", "Aarmy"] which your code passes, only because the extra letter is also in the first word). The only case in which this is not the case ["ate", "date"] your code doesn’t pass. Your code should return false here, but returns true because your loop is only 3 letters long.
Think about this, and try to determine which word is longest. Hope this is of help to you.

1 Like