Basic Algorithm Scripting: Mutations using RegExp

Basic Algorithm Scripting: Mutations using RegExp
0

#1

Tell us what’s happening:
I am trying to use regular expressions to solve this. I run into an error on the return statement indicating that arr[0].test is not a function.
Can anyone help me understand why this is not working?

Thanks,

Your code so far


function mutation(arr) {
  let testStr = `[${arr[1]}]`;
  let testRE = new RegExp(testStr, 'ig');
  return arr[0].test(testRE);
}

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/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations


#2

According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test, the syntax for the test() method is regexObj.test(str).

Since arr[0] isn’t a regexObj but a string, using .test() throws an error.