What's wrong with my logic with this solution?

Tell us what’s happening:
So, the problem I’m having is for some reason the method I’m using isn’t going true when it should be. The problem calls for you to detect when the strings in arr[1] hold the same letters as arr[0]. So I made use of new RegExp to make a dynamic proof to be used. I used the wildcard period just so that it would look for anything that as any combination of the letters and the g and i tags so that it would reiterate and not be hampered by case identification. Despite this though, its still hampered by the case differences. It produces false well enough though, anything that’s suppose to be false seems to come out as expected. I’m beginning to think that all I made was a false machine.

Your code so far

function mutation(arr) {
let tester = arr[0];
let stringer = arr[1];
let wall = new RegExp(tester+".","gi");
let work =wall.test(stringer)
return work;

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Mutations

Link to the challenge:

It is possible to solve this using regExp .
I found this really helpful to learn about Regular Expresssions

You need to use around the variable in your RegExp using "[" tester "]" to test for any of the letters. You also need to add ^ and $ to your regExp as well identify the start and end of the string…

This is really helpful for testing regular expressions https://regex101.com/r/2ST2dB/1/

Thanks for the two links, regexp tester will be a serious time saver. I also tried to work $ and ^ into the works, with various levels of success. My problem seems to stem from the fact that test() is putting out an incorrect boolean due to the fact that its matching either part of the string to the regex and throwing out true or not matching anything like its suppose to and giving me all falses. The question becomes as how to alter my regex to avoid this. This right here is why I’m very happy with your regex101.com, I’d never have confirmed that portion of the problem out without it. I’m beginning to think I’ll have to split the array in my regex or string to get a better answer, but I’m not one hundred percent sure that will work as intended. hmmm.


const wall  =  RegExp("^[" + arr[0] + "]+$", "ig")
arr = wall.test(stringer)
return arr

That worked perfectly. I just can’t figure out why it worked for this particular combination. I put in one that was very similar to this, near identical actually, but it didn’t pass for whatever reason. What’s the difference between :
const wall = RegExp("^[" + arr[0] + “]+", "ig") and let wall = RegExp("^"+"["+tester+"]"+"
Hmmm, does storing the arr[0] in a variable change it in some capacity or is it something else that I’m just not seeing?

Or nevermind, I’m just blind as a ***** bat and didn’t see my fingers had lacked to stumbled over the dollar sign in their haste at the very idea of looking for the various solutions and had instead replaced that dollar sign with a question mark. (I’m beginning to think I’m a slight bit dyslexic…that or my fingers are)

1 Like

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