Introduce RegEx before "Check for Palindrome" problem
See original GitHub issueCheck for Palindrome continues to be difficult to surmount for beginners in JavaScript.
This challenge has two parts to it:
- Process the input string
str
to remove non-alphanumeric characters from it. - Use some logic to find palindromes.
This is the third challenge in Basic Algorithmic Challenges, and the two that comes before this, introduce the camper to recursion and String-to-Array with reverse()
, split()
, and join()
.
In this challenge, the camper needs to come up with a non-trivial regular expression, to remove non-alphanumeric characters from the input string str
.
And here’s the kicker - \w
does correspond to alphanumeric characters [0-9]
and [a-z]
(and also [A-Z]
, but not relevant to this challenge, because we do case insensitive matching); but it also includes underscore _
. The test cases indicate you have to exclude underscore.
I recommend introducing the camper to regular expression, with 1-2 problems before that, and teach them how to form and test their RegEx. At the very least, they should be able to use something like regex101.
Ideally, I would want a full-fledged curriculum dedicated only to RegEx. I have seen even experienced campers fear regular expressions (I am not experienced, but I fear it too!). If this issue is accepted, I can work with others on the core-team on getting a curriculum on RegEx on the live site.
I know that there are four problems that refers to regular expression:
- Sift through text with regular expressions
- Find numbers with regular expressions
- Find whitespaces with regular expressions
- Invert regular expression matches
But none of them makes the camper comfortable forming non-trivial complex regular expressions. And in later challenges, like US telephone numbers, regular expression makes the difference between solved and unsolved.
Besides, these four problems are from optional part of the curriculum. In the helpful links section for the palindrome problem, we can at least point them to these.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:14 (12 by maintainers)
Top GitHub Comments
@deesto the tutorial on regexone is cool! But it also has its deficiencies.
As I have mentioned above, it lets you continue without having to fully match Strings given. But the biggest problem I see with tutorials like regexone and similar others, is this: it’s isolated
Let me explain what I meant by that: most people learn RegEx step by step (groupings, tokens, extracting) then they move on with their life. They would never use it unless there is absolutely no other way.
You won’t use RegEx as often as you would use conditionals or loops or recursion in your code. Even when you would have to use, you would most likely Google for some existing ones and copy-paste for lack of time.
Our aim is to form the RegEx curriculum in a way that it feels organic, with lot of practical use-cases. We would like to make the camper feel at-home using regular expressions.
As for reinventing the wheel, it’s not a massive undertaking, compared to some of the things we have built so far and more so planning to build.
@QuincyLarson Here is some proposed curriculum: https://github.com/FreeCodeCamp/FreeCodeCamp/issues/5794