re: Code Golf Challenge: Palindrome Detector VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Nice! You can make the function even smaller if you just returned Array.from(word) .reverse() .join("") === word
 

Even shorter

word.split('').reverse().join('')==word

This wouldn't work for "Arara" would it? It'd need some sort of case normalisation.

Also, what about "Taco cat".

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
code of conduct - report abuse