Basic Algorithm Scripting - Mutations

Hey I’ve tried to solve this challenge with a RegExp but I couldn’t make it work. I still don’t understand why there has to be a $ in [^${arr[0]}]. Can someone please explain this to me?

function mutation(arr) {
  const regex = new RegExp(`[^${arr[0]}]`, 'i');
  return !regex.test(arr[1]);
}

mutation(["hello", "hey"]);

Challenge: Basic Algorithm Scripting - Mutations
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.

For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case.

The arguments ["hello", "hey"] should return false because the string hello does not contain a y.

Lastly, ["Alien", "line"], should return true because all of the letters in line are present in Alien.

Link to the challenge:

Because it is an expression inside the template literal. It isn’t a regex Boundary-type assertion.

1 Like

Thank you very much I was so stuck I didn’t came into my mind. Now I see :slight_smile:

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