Javscript basic algorithms mutation

hello please can anyone tell me why this doesnt work to solve mutation challenge in basic algorithms ( js curriculim)

     function mutation(arr) {
var arr1=arr[0].toLowerCase();
var arr2=arr[1].toLowerCase();
var hamza=/arr2/;


if(hamza.test(arr1)){
  return true 
}





  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/88.0.4324.182 Safari/537.36.

Challenge: Mutations

Link to the challenge:

Yeah, I’m not sure, that this will work with a regex. Just one example:

mutation(["floor", "for"]) should return true.

But if you take the regex /for/ and test it against ‘floor’ it returns false, because the pattern ‘for’ is nowhere in the word floor. but it should return true, because all of its letters are included in the word ‘floor’.

So understand this: Your regex checks for that specific pattern, in that specific order.

To be more precise, it doesn’t even check for the value of arr2.
The correct way to declare the regex would be like this:
var hamza= new RegExp(arr2)
The way you are doing it, it will look not for the value of the variable ‘arr2’ but instead it will look for the pattern ‘arr2’.)

I think, you will be able to figure out how to solve it, if you look for something else than regex :wink:

1 Like

i understand now thanks a lot bro

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).