Mutations / Invalid flags supplied to RegExp

Mutations / Invalid flags supplied to RegExp
0
#1

Tell us what’s happening:
Hi Everybody,

My console returns to me : Invalid flags supplied to RegExp constructor ‘a’.
I would like to understand what’s wrong?
The purpose of this function is to match the arr[1] arg into the arr[0] arg , unsorted.

Your code so far


function mutation(arr) {
  let cut = arr[1].split('');
  let cut2 = arr[0].split('');
  var regex = new RegExp(...cut, '\gi');
  var result = regex.test(...cut2);
console.log(result);
}
mutation(["Mary", "Aarmy"]);

Your browser information:

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

0 Likes

#2

Acceptable flags are ‘gimsuy’. You have a backslash.

0 Likes

#3

whithout , I still have the same problem.
Invalid flags supplied to RegExp constructor ‘a’

0 Likes

#4

Yes, I just noticed. You’re splitting “Mary” and then passing it as arguments to RegExp. It takes first letter “M” as regex and second letter (“a”) as flag.

0 Likes