Closed mknecht closed 9 years ago
I haven’t done any performance testing on this, but turning the string into an array of characters only to turn it back into a string sounds like it would be more work than the current approach. That’s why I went for it.
I was curious, so I checked it out. You're right, @mathiasbynens. Your version is (much) faster.
Thanks for following up on this! Your comment made me remember one of the very first jsPerf tests ever created: https://jsperf.com/string-reverse
more a question than an issue: Why do you manually reverse the string in step 2? After step 1, the otherwise incorrect
string.split('').reverse().join('')
idiom should work, right? (Tried it and the tests work.)Is it for performance reasons? Because I would have thought copying a string over and over again yields O(n²), where the array approach would yield O(n).
Other than that thanks for the insightful article on esrever. :)