Basic Algorithm Scripting - Mutations

Here is the problem:

I’m not sure what is wrong in my code, but it fails one of the tests in this challenge. If anyone has any input on what is going wrong without giving the answer away. Thanks!

my code:

function mutation(arr) {

  var arr1 = arr[0].toLowerCase();

  var arr2 = arr[1].toLowerCase();

   arr1 = arr1.split(""); 

   arr2 = arr2.split("");

   for (var i= 0; i < arr2.length; i++){

       return arr1.includes(arr2[i])

   }

}


console.log(mutation(["hello", "hey"]));
//return true, should be false.
console.log(mutation(["ate", "date"]));
//returns false which is correct

Please share your code instead of a screenshot.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums

I went ahead and fixed that. Thank you.

I added some console logs and I think you can see the problem, namely you just return the outcome of comparing the first letter:

function mutation(arr) {

  var arr1 = arr[0].toLowerCase();

  var arr2 = arr[1].toLowerCase();

   arr1 = arr1.split(""); 

   console.log(arr1);

   arr2 = arr2.split("");

   console.log(arr2)

   for (var i= 0; i < arr2.length; i++){
      console.log(arr2[i]);
    
       return arr1.includes(arr2[i])

   }

}


console.log(mutation(["hello", "hey"]));
//return true, should be false.
console.log(mutation(["ate", "date"]));
//returns false which is correct

Console says:

[ 'h', 'e', 'l', 'l', 'o' ]
[ 'h', 'e', 'y' ]
h
true
[ 'a', 't', 'e' ]
[ 'd', 'a', 't', 'e' ]
d
false