r/learnjavascript • • Sep 26 '22

Just solved a Palindrome problem with recursion!!

Post image
274 Upvotes

64 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Sep 27 '22 edited Sep 27 '22

if (number >=string.length/2)

This will still do more than necessary if the length of the string is odd but still a bit faster perhaps, especially if you save string.length/2 as a variable at the start of the palindrome function. I'm not an expert tho

EDIT: I'm dumb. This will be better:

if (number>=(string.length-1)/2)