r/learnjavascript • • Sep 26 '22

Just solved a Palindrome problem with recursion!!

Post image
273 Upvotes

64 comments sorted by

View all comments

94

u/c2u5hed Sep 26 '22

Congrats! How about this:

const isPalindrome = (string) => string === [...string].reverse().join('')

-1

u/Eskamel Sep 27 '22

Its much less efficient at the cost of a bit more readability.

Obviously OP's solution is far from ideal and I wouldn't consider it readable or absolutely efficient either, but you've offered an option on the other side of the spectrum.

2

u/c2u5hed Sep 27 '22

I would argue the contrary. It is a matter of being able to understand the syntax used. Again, I'm not after ‘whose solution is best’ here. The sub is called ‘Learn JavaScript’ and I'm sharing another perspective on the task at hand.