Help with Mutations using regex

Tell us what’s happening:
am trying to make use of the regex skills i picked up earlier but its is not modifying

Your code so far

function mutation(arr) {
//arr.test((a,b) => a === b);

  //return arr[0]=== /arr[1]/i ? true: false;
 var cp = arr[0];
 var ts = arr[1];
 var rx = /ts/i;
  return rx.test(cp);

var result = mutation(["hello", "Hello"]);

Your browser information:

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

Link to the challenge:

You’re literally testing if the first string contains “ts”, as in those two characters.

You need to build a regex if you want to pass variables in: new RegExp(ts, "i").

However, this will still not work, because what you are trying to check is if all the letters in the second string are present in the first string. Doing the above will mean ["hello", "olleh"] will return false (it should return true).

Regex is not necessarily the best thing to use here: it is designed to find specific patterns of characters in a string. You are not looking for specific patterns, you just want to know that all the characters from one string are there in another string.

1 Like