4 ms·
This always comes up as a thing that people use as an interview question or an algorithm problem. But for what conceivable non-toy reason would you actually wa
by thrower123 6y ago
This always comes up as a thing that people use as an interview question or an algorithm problem. But for what conceivable non-toy reason would you actually want to reverse a string?
I have never once wanted to actually do this in real code, with real strings.
Furthermore, the few times I've tried to do something like this by being cute and encoding data in a string, I never get outside the ASCII character set.
- edflsafoiewq 6y agoAnd even ASCII can't do a completely dumb string reverse, because of at least \r\n.
- kps 6y agoTrivia/history question: There's a very good reason it's \r\n and not \n\r.
- btilly 6y agoThe commands were used to drive a teletype machine. Carriage return and newline were independent operations with carriage return physically taking longer. So \r\n allowed it to get to the next letter soon.
- macintux 6y agoGenerating a list through recursion often involves reversing it at the end, so I’ve reversed a lot of Erlang strings in real code.
- mprovost 6y agoTo index from the end of the string. If you want the last 3 characters from a string, it's often easier to reverse the string and take the first 3.
- saagarjha 6y agoMost languages that are good enough at doing Unicode are also modern enough to give you a “suffix” function.