Reverse a String Incomplete * Should i no this by now.?

So i have reached the section Basic Algorithm Scripting and my first question is on Reverse a String.
Now is it wrong that i have got to this point and DONT quite understand how it's done? or in your opinion is it ok to read or watch a video on how it's done .just wondering if maybe i am not taking it all in.

prob the cleanest version i found on this .
return str.split("").reverse().join("");

It’s ok to approach this however you like :slight_smile:

My method for solving problems with the algorithms is to think about what I have as a piece of data, in this case a string, and then looking up what methods I can use on that data type.

So in your example split() is an interesting one because it gives you a new data type (an array).

So then you can look up the methods on that, like reverse() and join().

Do be discouraged if you need to look things up though. The algorithm challenges are designed to stretch your problem solving reasoning and introduce you to new methods. Look up code if you need to, but always find out what it means and why it works :slight_smile:

Happy coding!

1 Like

My first solution was:

return [...str].reverse().reduce( (a,b) => a + b );

Thanks for ‘join()’! Now it is:

return [...str].reverse().join("");