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.
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
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.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original posterâs question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.