Mutations - what's the proper way to use .includes in this case?

I dissecting both arrays into elements and I am stuck on the last step when it comes to compare the two, is .includes the best way to accomplish this ?

Thank you,

  **Your code so far**

function mutation(arr) {
arr.toLowerCase;
const splitted0 = arr[0].split("")
const splitted1 = arr[1].split("")
for (let i = 0; i < arr[0].length; i++) {
  if (splitted1.includes(splitted0)) {
    return true
  }
}
}

console.log(mutation(["hello", "hey"]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0

Challenge: Mutations

Link to the challenge:

I’m not sure there is a “best” way to complete this challenge. There are a few ways to determine if an element exists in an array. The includes method is one of them. You could also use the indexOf method.

I don’t think this is your main issue though. I think you have a basic logic error you need to address. I think it will become clear if you choose better variable names. The first element in arr is the string you are testing. It’s the subject of the test. So think of a name that would reflect this and use that instead of splitted0. The second element in arr contains all of the letters you want to test with. So think of a name that would reflect that and use it instead of splitted1. After doing this I think it will be more obvious how your for loop should be written.

Also, currently you are passing an array into the includes method. I don’t think this is what you want. You want to pass an individual letter into the method, right?

One last hint, the instructions say that you should ignore case, so you’ll need to take that into account as well.

1 Like

If I understand you, so far it’s not accomplishing the task at all - so kinda weird question.

Generally speaking… dunno if it would be the best method, it certainly would be more efficient by account of using a built-in-function which generally are considered better. But I cannot say if it would be the best method overall.

That said, it doesn’t matter all to much. If you can solve the challenge with whatever logic you feel like, that’s good. So that’s what you gotta work on.
Right now, I looked at how this runs and there are a couple of issues.
First off arr.toLowerCase doesn’t exist - you REALLY need to check that first and/or console.log() the result. Debugging will be a nightmare if you just throw in methods that sound good.
Second off: the loop is currently not using the counter i at all.
Third off: the return will not work this way. Think about when the function should return true and when not.

1 Like