Clean code question

Clean code question
0

#1

So i just solved the reverse a string challenge with this code
function reverseString(str) {
var array = [];
var newArray = [];
var stringBackwards = ‘’;
array=str.split(’’);
newArray = array.reverse();
stringBackwards = newArray.join(’’);
str = stringBackwards;

return str;
}

reverseString(“hello”);

It worked and I am very happy that I figured it out. However I was just curious if down the road this would be acceptable due to its long and complicated appearance. In my googling of how to do the challenge I found this code:
var strReverse = str.split(’’).reverse().join(’’); which did the same job as my code but looks much nicer. So should I be shooting for as little code as possible or should I just worry about figuring it out and cleaning up later with the more I learn?
Thank you


#3

Thank you very much for your input. Onward to more learning!!!