Oh.. why? Why should we work on theoritical algo problems when we could develop the next Instagram or Salesforce.com?
Because, son - you have to learn the different paths to glory. Why take the longer path when it can be shorter?
That aside: let us look at multiple ways of reversing a string in Javascript.
The best and easiest way
Convert to array and back.
|
|
Prove that I know ‘modern’ functions
Aka - use reducer to reverse.
|
|
Or, just use a for
.
More of the same
Yep, more ESXX. Use a map.
|
|
Be super object oriented in the wrong language
In fact you can use prototypes everywhere, but below is a cool implementation using RTL override.
You may have to use browser console if you are unable to see this code in action in your favourite console.
|
|