Basic Algorithm Scripting: Mutations: "hello".includes("h", "e", "y") returns True?

Tell us what’s happening:

The code passes all the tests except for the first one which tests if all the characters from “hey” is inside “hello”. I tried to test it by doing

console.log("hello".includes("h", "e", "y"));

and this is evaluating to True… If I change the ordering around for “hey”, it returns false sometimes, but not always… Is this a bug?

  **Your code so far**

function mutation(arr) {
var lowerCase = arr.map(string => string.toLowerCase());
return lowerCase[0].includes(...lowerCase[1]);
}
console.log("hello".includes("h","e","y")); // Evaluates to True for some reason
console.log(mutation(["hello", "hey"]));
  **Your browser information:**

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

Challenge: Mutations

Link to the challenge:

I think you’ll find the solution if you check the documentation for Array.prototype.includes:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

(if a function is written to only process one argument, you can pass in as many as you like, the rest will just be ignored)

1 Like

This just isn’t how includes works

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes

The additional arguments are not extra strings to check.

Doh, that is on me. I should’ve read up on the documentation again. Thank you.

Thank you! Didn’t realize it.

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