Check if a phrase's letters and digits read the same reversed
A word-game app lets players submit phrases that read the same in both directions, such as "Step on no pets!". Players type naturally, with capitals, spaces, punctuation, and sometimes emoji, so the check has to look past all of that.
Implement isPalindromePhrase(text). It returns true when the letters and digits of text read the same forwards and backwards, and false otherwise.
isPalindromePhrase(text) // => boolean
a–z, A–Z) and digits (0–9) count. Every other character (spaces, punctuation, symbols, emoji, accented letters) is ignored.'R' matches 'r'. Digits compare as themselves.true or false, not a truthy or falsy value.text can be tens of thousands of characters long, so the check must run in linear time.isPalindromePhrase('Step on no pets!'); // => true
isPalindromePhrase('Was it a car or a cat I saw?'); // => true
isPalindromePhrase('RaceCar'); // => true
isPalindromePhrase('12:21'); // => true ('1221')
isPalindromePhrase('Frontend Lead'); // => false
isPalindromePhrase('1 0'); // => false ('10')
isPalindromePhrase('🙂 Wow 🙃'); // => true ('wow')
isPalindromePhrase('?!'); // => true (nothing to compare)
isPalindromePhrase(''); // => true