DEV Community

Discussion on: Code Golf Challenge: Palindrome Detector

 
quickhand profile image
quickhand • Edited

The issuer of the challenge, David, said:
"Lets keep it simple: only checking for words. No handling for spaces, punctuation or numbers."

But if we're handling capitals and spaces, how about:

let p=s=>(t=>[...t].reverse().join("")==t)(s.toLowerCase().replace(/\s/g,""))

Here,

p("Taco cat") //returns true,
p("Arara") //returns true

Another slight mod and we can ignore all non-letter chars (numbers, punctuation, etc.):

let p=s=>(t=>[...t].reverse().join("")==t)(s.toLowerCase().replace(/[^A-z]/g,""))

p("A man, a plan, a canal: Panama.") // returns true