DEV Community

Cover image for How to Solve Palindrome Problem with 1 Line of JavaScript

How to Solve Palindrome Problem with 1 Line of JavaScript

Amit Mehta on August 03, 2022

Unless you're just learning how to code now, you've probably heard of the famous valid palindrome or 'is palindrome' problem. It's a common techni...
Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

Why so long and complex?

const isPalindrome = a => [...a].reverse().join('') === a
Enter fullscreen mode Exit fullscreen mode
Collapse
 
lnquy065 profile image
Quy Luong

it's properly right, but I think in coding interview we can't do like that 😁

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

If I were interviewing a candidate and they gave me that solution, I'd be perfectly happy - it shows knowledge of modern JS and is an efficient solution.

Collapse
 
apmfree78 profile image
Amit Mehta

nice! interviewer may bawk at using reverse(), but hey if you can do it in 1 line, why not! 🀣

Collapse
 
simcha profile image
Simcha

:(
I read the post, and I don't understand why the author rowed...
And you confirmed my suspicions.

Collapse
 
coditdoc profile image
Codeitdoc7 • Edited

What if throw in some random characters. Like - ra@c#ec_aR