Any string, after removing whitespaces and punctuations, that reads the same when the order of letters is reversed - regardless of the case of letters - is considered a palindrome. For example:
'Was it a car or a cat I saw?'
So the steps involved are:
- Convert the string to uniform case
- Remove all non-alphabet characters from the string
- Reverse the order of letters and check if it reads the same as the original string
const str = "Was it a car or a cat I saw?";
[...str.toLowerCase().replace(/[^a-z]/g, '')].join('') ===
[...str.toLowerCase().replace(/[^a-z]/g, '')].reverse().join('')
Top comments (0)