MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/xosb9d/just_solved_a_palindrome_problem_with_recursion/iq2ac9a/?context=3
r/learnjavascript • u/KayteeFly • Sep 26 '22
64 comments sorted by
View all comments
2
If you want to save time, you could change line 10 so that it only needs to reach halfway thru the string, rather than the entire string
1 u/KayteeFly Sep 27 '22 Teach me please ! 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 thoEDIT: I'm dumb. This will be better:if (number>=(string.length-1)/2)
1
Teach me please !
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 thoEDIT: I'm dumb. This will be better:if (number>=(string.length-1)/2)
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)
2
u/[deleted] Sep 27 '22
If you want to save time, you could change line 10 so that it only needs to reach halfway thru the string, rather than the entire string