Mutations with method .includes

Mutations with method .includes
0

Tell us what’s happening:
Hello everyone,

I tried to solve this JS challenge with .includes().

The code below can pass every other test, except mutation([“hello”, “hey”]);

Why??? It bothers me so much:thinking:

Thanks!

Your code so far


function mutation(arr) {
let firstString=arr[0].toLowerCase().split("");
let secondString=arr[1].toLowerCase().split("");
for (let i=0;i<secondString.length;i++){
if(firstString.includes(secondString[i])){
return true;
}else{
return false;
}
}}
mutation(["hello", "hey"]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36.

Challenge: Mutations

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations

Hey @ayten1871, try to read your code as an interpreter would - line by line. What does this if statement do?

if(firstString.includes(secondString[i])){
  return true;
}

Cheers!

1 Like

Thank you for your kindly reply, it helps a lot:smiley: