Any way to do it using regular expression?

Tell us what’s happening:
Describe your issue in detail here.
I’ve tried solving this problem using regular expression and almost all of the questions are working perfectly, except three. Can someone help me here?

  **Your code so far**

function mutation(arr) {
//the word
let toSearch=[...arr[0].toLowerCase()].sort().join("");
//the word to be searched
let pattern=[...arr[1].toLowerCase()].sort().join("");
console.log(toSearch,pattern)
//using regexp to find if it exists or not
let check= new RegExp(pattern,"ig");
let result=check.test(toSearch);
//return the result
return result
}

mutation(["hello", "hey"]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36

Challenge: Mutations

Link to the challenge:

The last test is passing in the following array:

[ 'Noel', 'Ole' ]

Your function creates the following variables with that:

check = /elo/gi;
toSearch = elno;

Your function is returning false for this but it should return true. Do you see why?

There might be a way to use pattern matching to solve this but I do not think it is the obvious solution.

1 Like

I see. That’s why it was not passing the test even though I thought I’ve written every thing carefully. Thanks

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