Mutation with includes method

I tried to solve this problem with Array.includes method.
It passes all cases, except [“hello”, “hey”] . Maybe this method is not ideal for this challenge, but I wanna know, why this code doesn’t work only for first case. :woman_shrugging:
Could someone tell me why?

  **Your code so far**

function mutation(arr) {
let firstLetters = [...arr[0].toLowerCase()];
let secondLetters = [...arr[1].toLowerCase()];

const comparing = (first, second)=> {
  return first.includes(...second);
return comparing(firstLetters, secondLetters);

console.log(mutation(["hello", "hey"]));// why true???? 
console.log(mutation(["Mary", "Army"]));//true
console.log(mutation(["voodoo", "no"]))//false
  **Your browser information:**

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

Challenge: Mutations

Link to the challenge:

Using includes is fine, but you can’t just do what you’re doing here. The includes function takes one argument. JavaScript functions can take any number of arguments, so it will not error, it will just ignore the rest. This is working by accident, because:

For example, Mary/Army, the comparing function asks

[m, a, r, y].includes(a, r, m, y)

It ignores r, m, y, so

[m, a, r, y].includes(a)

Is true



Is also true

You need to loop, the every method might be useful

oh I see. I should’ve known more about this method property. Meanwhile I found an answer still with includes method but in for loop. Thank you for your answer!! :slight_smile:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.