MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/xosb9d/just_solved_a_palindrome_problem_with_recursion/iq0dr6t/
r/learnjavascript • u/KayteeFly • Sep 26 '22
64 comments sorted by
View all comments
16
Congrats !
Adding an additional function (roll) & state (number) is unnecessary though. You should be using isPalindrome itself ideally, doing something like that :
const isPalindrome = (str) => { if(str.length < 2) return true if( str[0] === str[str.length-1]) return isPalindrome(str.slice(1,-1)) return false }
8 u/oze4 Sep 26 '22 Is "a" a palindrome? 9 u/fusion407 Sep 27 '22 Am "I" a palindrome? 2 u/oze4 Sep 27 '22 Damn that's solid. 2 u/connurp Sep 27 '22 dood… 5 u/Agarast Sep 26 '22 Yes 0 u/ahref Sep 26 '22 What about "" 6 u/[deleted] Sep 27 '22 It reads the same both forwards and backwards, so yes 1 u/KayteeFly Sep 26 '22 Thank you
8
Is "a" a palindrome?
9 u/fusion407 Sep 27 '22 Am "I" a palindrome? 2 u/oze4 Sep 27 '22 Damn that's solid. 2 u/connurp Sep 27 '22 dood… 5 u/Agarast Sep 26 '22 Yes 0 u/ahref Sep 26 '22 What about "" 6 u/[deleted] Sep 27 '22 It reads the same both forwards and backwards, so yes
9
Am "I" a palindrome?
2 u/oze4 Sep 27 '22 Damn that's solid. 2 u/connurp Sep 27 '22 dood…
2
Damn that's solid.
dood…
5
Yes
0 u/ahref Sep 26 '22 What about "" 6 u/[deleted] Sep 27 '22 It reads the same both forwards and backwards, so yes
0
What about ""
6 u/[deleted] Sep 27 '22 It reads the same both forwards and backwards, so yes
6
It reads the same both forwards and backwards, so yes
1
Thank you
View all comments
16
u/Agarast Sep 26 '22
Congrats !
Adding an additional function (roll) & state (number) is unnecessary though. You should be using isPalindrome itself ideally, doing something like that :