Mutations Algorithm Challenge Help

Hello all,

I’ve been having some trouble getting all of the different inputs to work with my script for the mutations algorithm challenge. For example my code is not comparing “hello” and “hey” properly. It’s returning true, which doesn’t make sense since ‘l’ and ‘o’ are not present in ‘hey’.

function mutation(arr) {

var str1 = arr[0].toLowerCase().split('');
var str2 = arr[1].toLowerCase().split('');
var status = false; 

//Loop through each character of str1
for(var i = 0; i < str1.length; i++){
  //Check if character is present in str2 
  //If character is present is str2 change status to true 
  status = true;
  //If the character is not present in str2..
  //Change status to false and immediately return the status 
  status = false;
  return status; 
//Return the status of true, each characters in str1 was in str2 
return status;

mutation(["hello", "neo"]);

I’m not looking for any specific answers, but more so some guidance to why my functions isn’t working as I think it is.

If the character is not present, indexOf returns -1 which is not falsy.

1 Like