How to begin Reverse a String algorithm?

So I’m trying to talk out loud this algorithm and break the problem down piece by piece.

Here’s what I understand so far and hopefully the forum can help fill in the blanks.

So I understand I probably will need to store this string into an array.

Once the string is into the array I would probably need to split() the string and store it into a new array. This new array will divide each character. Something like this.

var oldArray = [Hello World]
var newArray = [H e l l o W o r l d] // this a new string with each character in its own individual index.

After the array is split() I probably need to reverse the entire newArray and then join() the characters back into the old array.

Once this is done I need to turn the array back into a string an again. Does my logic sound right?

You have an extra array step both before and after reversing. You can go straight from "Hello World" to ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'] and you can go straight from your reversed array back to a string.

Hello ArielLeslie,

Thank you for your quick response. Here is my question.

How do I store strings into an array? I understand how to use a for loop to iterate through integers, but I don’t know how to take each character and make its own index. Like this below.

[‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ’ ', ‘W’, ‘o’, ‘r’, ‘l’, ‘d’]

Is there something I can review to do this?

I believe that the challenge description recommends that you research the split() function.

look at this, you might like this little cheat hidden in the JS docs:

var str = 'asdfghjkl';
var strReverse = str.split('').reverse().join(''); // 'lkjhgfdsa'
// split() returns an array on which reverse() and join() can be applied

Okay this is what I’ve so far. I think its coming along very nice.

function reverseString(str) {

var newArray = str.split(’’);

var newArray2 = newArray.reverse();

var newArray3 = newArray2.join();

str = newArray3.toString();

return str;

}

reverseString(“Greeting from earth”);

However I don’t know to convert an array back to a string. My output is this below.

h,y,r,a,e, ,m,o,r,f, ,g,n,i,t,e,e,r,G

It should be back back to its original string. Any ideas on what I should do?

I figured it out and I passed the test…but I really don’t understand this ‘’ and this ’ ’ separators

Like why does ‘’ put commas and ’ ’ put spaces? That’s weird to me. lol

I get it. Makes sense now. Thank you for your help. On to the next.

@camperextraordinaire its right there in the docs… I couldn’t believe my luck when i found it.
I get your point though.

I had to take a few days off. I’m back working on this algo again… I’m going to check the doc like @Feight. lol