freeCodeCamp / curriculum

The freeCodeCamp curriculum and lesson editor
Creative Commons Attribution Share Alike 4.0 International
81 stars 124 forks source link

Fix/commenting out #266

Closed HadrienAllemon closed 6 years ago

HadrienAllemon commented 6 years ago

Description

In the challenge Basic JavaScript: Using Objects for Lookups The user has to get rid of any switch statement inside the code. I added a regex to the inspected code so that if the user simply comment out the switch statements, they're still able to pass the challenge.

On a side note, I do not know why, but I wasn't able to escape any character inside the regex's in the JSON file. I gathered it's because the characters are escaped from the string rather than from the regex, creating an error. So I had to improvise and put any character that needed escaping inside square brackets.

I also added another change, a typo in the 19th challenge of basic html and html 5, but I think it was solved by someone else not long ago.

Pre-Submission Checklist

Checklist:

Closes https://github.com/freeCodeCamp/freeCodeCamp/issues/17981

Nirajn2311 commented 6 years ago

@HadrienAllemon yeah I have already done a PR for the typo. Also could you post the regex statement here and I’ll convert it so that you can paste in the json file.

HadrienAllemon commented 6 years ago

assert(!/case|switch|if/g.test(code.replace(/([/]{2}.*)|([/][*][^/*]*[*][/])/g,''))

so the statement is /([/]{2}.*)|([/][*][^/*]*[*][/])/g and previously was /(\/{2}.*)|(\/\*[^/*]*\*\/)/g before I had to convert it into " npm friendly "

Thanks a lot for your help!

scissorsneedfoodtoo commented 6 years ago

@HadrienAllemon, just played around with your original regex statement and I believe this should work as intended:

/(\\/{2}.*)|(\\/\\*[^/*]*\\*\\/)/g

Some special characters like the backslash need to be double escaped in JSON strings. It's something that trips me up all the time. But your clever workaround using the brackets works just fine, so I'll go ahead and merge this now.

Thanks for your contribution!