Implement the Mutations Algorithm - Implement the Mutations Algorithm

Tell us what’s happening:

I’ve tried this a couple different ways and I think this is nearly what’s needed.

When I run a console.log of Char in the ‘for’ loop it skips the first letter if they don’t match and I don’t undertand why it’s skipping the first letter

Your code so far

function mutation(arr) {
  let tester;
  let firstString = arr[0].toLowerCase();
  let secondString = arr[1].toLowerCase();
  for (const char of secondString)
  if (firstString.includes(char)) {
    tester = true
    
  } 
  else {
    tester = false
  }; return tester
};

console.log(mutation(["hello","hey"]));


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Implement the Mutations Algorithm - Implement the Mutations Algorithm

Try adding couple console.log calls to try to figure out what’s happening. Ie. just before tester is returned, or what’s the tester for each character.

that’s what I tried to do but explained it really badly,

when I run console.log(char) for [hello, neo] it skips the first letter of ‘neo’ is there a way to force it to check the first letter instead of starting at the first ‘true’ iteration?

Are you sure it’s skipped? How that could be confirmed?

function mutation(arr) {
  let tester = false;
  let firstString = arr[0].toLowerCase();
  let secondString = arr[1].toLowerCase();
  for (const char of secondString)
  if (firstString.includes(char)) {
    console.log(char)
    tester = true
    
  } 
  else {
    tester = false
  }; return tester
};

console.log(mutation(["hello","neo"]));

the console.log for ‘char’ give ‘e,o’ meaning it is ignoring the ‘n’ and I can’t figure out how to stop the loop to account for the ‘n’

But wouldn’t this branch of the if/else not get executed in case of n, as it’s not included in hello? Is the else branch executed for it?

Thank you for the hint