Need help with "Mutations"

Need help with "Mutations"
0

#1

Hey guys, I can’t seem to satisfy most of the conditions and I can’t figure out why.
Here is my code for the Mutation functions

function mutation(arr) {
  var word1;
  var word2;
  word1  = arr[0].split('');
  word2 = arr[1].split('');
  word1 = word1.sort();
  word2 =  word2.sort();
  
  for (var i = 0 ; i < word2.length; i++){
    if(word1.indexOf(word2[i]) !== -1 ){
      return false ; 
    }
    else {
      return true;
    }
  }
  }

mutation(["Alien", "line"]) ; //returns false when it should return true

Can someone tell me where I am screwing up in my code? Thanks!


#2

You are actually very close! Here is a hint (in case it’s too faint—there is a blurred spoiler below):

['A'].indexOf('a'); // -1

It’s worth noting that sorting the array is strictly not in your code.

Good luck! :smile: