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.
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.
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