Yep. Also remember your usage scenario.
Are you in a browser ?
How large is the string ?
How many strings ?
Because if you're only reversing a 100 chars string, even 1000 chars, the implementation (amongst thoses proposed in this thread) doesn't matter much performance wise (memory, duration, cpu cycles)...
For clarity and code comprehension, it's something else sure ^
This is a showcase, not a contest. Also, there is no point using reverse() to do a reverse operation. It's the same as trying to explain some term using the same term in a sentence.
This would be best solution. Yes it’s a re implementation of array reverse but it skips the split and join and only uses 2 bytes of memory and n/2 time
I think something like this would actually be the most performant:
Wouldn't it still take quadratic time?
My attempt:
That basically reimplements Array#reverse() from JS land at the second step.
Array#reverse() operates in-place, so there is no benefit here — you are doing exactly what
.reverse()
already does.This approach is unlikely to be more performant than the built-in method, and just takes more code to write and maintain.
Yep. Also remember your usage scenario.
Are you in a browser ?
How large is the string ?
How many strings ?
Because if you're only reversing a 100 chars string, even 1000 chars, the implementation (amongst thoses proposed in this thread) doesn't matter much performance wise (memory, duration, cpu cycles)...
For clarity and code comprehension, it's something else sure ^
This is a showcase, not a contest. Also, there is no point using
reverse()
to do a reverse operation. It's the same as trying to explain some term using the same term in a sentence.This would be best solution. Yes it’s a re implementation of array reverse but it skips the split and join and only uses 2 bytes of memory and n/2 time
Oh it’s not what I thought it was