JavaScript Palindrome Checker
Requirements
- A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case and spacing.
- The input string must be filtered to remove all non-alphanumeric characters (punctuation, spaces and symbols).
- The palindrome check must be case-insensitive.
Implementation
The function palindrome(str)
checks if the given unfiltered input string str
is a palindrome. Returns true
if the given string is a palindrome, false
otheriwse.
Example Usage
Use the browser console to interact with the function (Ctrl + Shift + I
, then select the "Console" tab):
> palindrome("racecar"); // true
> palindrome("RaceCar"); // true
> palindrome("race CAR"); // true
> palindrome("blizzard"); // false
> palindrome("fireball"); // false
> palindrome("wind"); // false