Tell us what’s happening:
Hey everyone!
So, as I was working through this problem and trying to find alternate solutions, I came across something interesting which I don’t understand.
Please review the code below and help me understand why this does not work. From my thinking the logic should work, but the {mutation([“hello”, “hey”])} test keeps returning true!?!
I’m lost…
Your code so far
function mutation(arr) {
//creates a var for index 0 and 1 which sets them to lowercase and converts to array
let x = arr[0]
.toLowerCase()
.split(“”);
let y = arr[1]
.toLowerCase()
.split(“”);
//should be able to test x for all of var y
return x.includes(…y);
}
mutation([“hello”, “hey”]);
console.log(mutation([“hello”, “hey”]))
//should return false, but returns true
//this code passes all other tests in this section except [“hello”, “hey”]
function mutation(arr) {
//creates a var for index 0 and 1 which sets them to lowercase and converts to array
let x = arr[0]
.toLowerCase()
.split("");
let y = arr[1]
.toLowerCase()
.split("");
//should be able to test x for all of var y
return x.includes(...y);
}
mutation(["hello", "hey"]);
console.log(mutation(["hello", "hey"]))
//should return false, but returns true
//this code passes all other tests in this section except ["hello", "hey"]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Mutations
Link to the challenge: