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
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice! You can make the function even smaller if you just returned
Even shorter
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:
Here,
Another slight mod and we can ignore all non-letter chars (numbers, punctuation, etc.):