While, reverse-ing and join-ing a big array of letters might be slow too 😉
I think Katas are rarely good for training optimization skills, but often for problem solving skills.
Usually optimization is done after the problem is solved (or bigger feature implemented) and we've measured and found issues with performance. Palindromes are often short, but your point holds: this method's performance should be measured in practice.
And in real life projects I tend to write more readable and flexible code 🙂
P.S. I'm particularly proud with this kata solution:
I think you also only need to compare the string length /2 +1 in order to check whether it's a palindrome because the first half actually needs to be the same like the last half only in reverse order right? So a for loop and then accessing the index of the string for the length /2+1 might be the fastest solution?
Similar to your functional approach:
Hey Kostia,
nice use of
every
!Maybe it will be very slow when the input string is very long,
Good point, Michael, it might!
While,
reverse
-ing andjoin
-ing a big array of letters might be slow too 😉I think Katas are rarely good for training optimization skills, but often for problem solving skills.
Usually optimization is done after the problem is solved (or bigger feature implemented) and we've measured and found issues with performance. Palindromes are often short, but your point holds: this method's performance should be measured in practice.
And in real life projects I tend to write more readable and flexible code 🙂
P.S. I'm particularly proud with this kata solution:
Okay, I'm enjoying posting weird solutions :)
Surely, I wont write such code IRL
I think you also only need to compare the string length /2 +1 in order to check whether it's a palindrome because the first half actually needs to be the same like the last half only in reverse order right? So a for loop and then accessing the index of the string for the length /2+1 might be the fastest solution?
yep, it would probably be the fastest solution