DEV Community

loading...

Discussion on: Code Golf Challenge: Palindrome Detector

Collapse
quickhand profile image
quickhand

Short:

let p=s=>![...s].some((c,i,a)=>c!=a[a.length-i-1])

Shorter:

let p=s=>[...s].reverse().join("")==s

In both:

p("potato") //false
p("racecar") //true

(First works on palindromic arrays of characters as well as strings, second only on strings)

Collapse
daveturissini profile image
David Author

Nice. Really like the approach with “some” in your first example