Implement the Mutations Algorithm - Implement the Mutations Algorithm

Tell us what’s happening:

I can’t figure out where it’s running into an issue validating that the individual characters match up. The console log is showing that the split was successful and the individual characters have been isolated, but it wont clear.

Your code so far

const cat = ["hello", "Hello"]

function mutation(array) {

  let newArray = array.map(strings => strings.toLowerCase().split(""));

  for (let i = 0; i < newArray.length; i++) {
    if (newArray[0].includes(newArray[1])) {
      return true
    }
    else {
      console.log(newArray[0])
      console.log(newArray[1])
      return false
    }
  }

}

console.log(mutation(cat))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 OPR/130.0.0.0 (Edition std-2)

Challenge Information:

Implement the Mutations Algorithm - Implement the Mutations Algorithm

Could you explain how the code is supposed to work?

The function starts off by returning a new array, assigned to the variable newArray, where the contents of the array are all set to lower case. It then uses the split method on that array to isolate the individual characters of the strings in the array so that I can see what letters we need to check for. the for loop iterates through the newArray variable and checks to see if the characters in the indicated first iteration of the array, match those of the indicated second iteration of the array. if they match up it should = true, and if not it should = false. Do i need to iterate through the separated segments?

are you sure? where are you using i? what happens when return is executed?

you can see what your function is doing line by line with a tool like https://pythontutor.com/

After banging my head against the wall I realized I was having issues truly understanding what my for loop was returning and decided to go back to the basics. I will be reviewing string methods and re-learning loops to really learn how to explain what I’m doing / trying to do