Even with the code I used in the Palindrome Checker to remove special characters, I still have these errors ‘removeSpecialChars should remove signle quotes / double quotes / underscores’.
I don’t understand what’s happen. When i log the value returned by my function with the parameter : ’ " Hi!_There’’ " the function returns “HiThere”.
My function has the behavior waited so I don’t see what I need to change to pass these tests.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const removeSpecialChars = (string)=>{
return string.replace("[^A-Za-z0-9]/g","")
}
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Challenge Information:
Learn localStorage by Building a Todo App - Step 67
I tried again and again to find the solution and finaly I just made a regex which find single quote, double quote and underscore but i think this solution is less elegant than the solution which use this regex :
/[^a-zA-Z0-9]/g
I tried to remove double quotes and add slashes as you mentioned so i obtained this code, but once again, the test didn’t pass :
return string.replace(/[^a-zA-Z0-9]/g,"")
I loged the result of this call :
removeSpecialChars("_"Hi! There'_");
And obtained this result : HiThere
The waited behavior is respected, so I still don’t understand why this solution is not accepeted ?
is working because the regular expression includes characters like ', ", /, and _. This regex targets only these specific characters and removes each occurrence in the string.
The reason spaces are also removed because the curriculum challenge test are specific about the challenge instructions.
the regex /[^a-zA-Z0-9]/g removes all non-alphanumeric characters, which could include spaces or other symbols that the challenge test might require to keep.