Palindrome check
A JavaScript exercise from Scriptdrill. Solve it with a code editor in your browser that runs your function against example and hidden tests, and it is checked the moment you submit.
The task
Return `true` when `s` reads the same forwards and backwards, looking only at letters and digits and ignoring upper and lower case. Spaces and punctuation are skipped, so `"A man, a plan, a canal: Panama"` is a palindrome. A string with no letters or digits counts as a palindrome. Letters are plain English letters.
What this exercise teaches
Normalizing before comparing keeps the check itself trivial. The class in the replace has to keep digits as well as letters: dropping digits would turn 1a2 into a and call it a palindrome.
A hint if you get stuck
Clean the string first: lowercase it and remove everything that is not a letter or a digit, for example with `replace(/[^a-z0-9]/g, "")`. Then compare it with its reverse.
Try it now, free, no account needed
Every exercise on Scriptdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. The worked solution opens once you solve it or after two tries.
Open this exerciseMore exercises in Basics
- Total of a listFree
- Items in stockFree
- Full namesFree
- Has every tagFree
- Reverse the wordsFree
- Capitalize each wordFree
- Count the vowelsFree
- Clamp a numberFree
- Range of numbersFree
- FizzBuzzFree
- Anagram checkFree
- Fibonacci numbersFree
- Roman numeralsFree
- Balanced bracketsFree