Can someone smarter than me make this look pretty. Map #237

Can someone smarter than me make this look pretty. Map #237
0.0 0


I hacked this together in a few minutes. I have to leave the computer RN but i would like to see a cleaner/refactored version of what i came up with… just to help me understand better or start better habits.

Reverse the provided string.
You may need to turn the string into an array before you can reverse it.
Your result must be a string.

function reverseString(str) {
var firstArray = "hello";
var array = [];
array = str.split('');
var newArray = array.reverse();
var lastArray = array.join('');
   return lastArray;

i just went step by step split, reverse, join… thus the plethora of var’s with the name array in it.


I won’t give you a solution, but you should know that you can chain method calls together. For instance:

["h", "e", "l", "l", "o"].join().toUpperCase() // "HELLO"


function reverseString(str) {
var array = [];
array = str.split(’’).reverse().join(’’);

return array;



You pickup habits along the way, don’t worry too much about efficiency in the beginning. Most of what you’ll think of as efficient might not be (aka you can make an entire problem in one line if you want). Distinguishing between elegant solutions and horrible solutions is something that comes with time and experience, you need to factor in code clarity, computer resources (aka you can map a string 4 times to get data from it, or you can map once and get all the data, the latter will be more elegant) and other things that just don’t show up in the beginning.

Overall, you shouldn’t worry so much about making good code, just try to understand whatever you do. The concept of “good” code is quite nuanced, specially in the beginning.


You can still do better! Why are you creating a variable?


I figured array had to be defined first even if its empty to start with. I never thought to run it without.