Reverse a string

So I’ve done FCC before, but I got so lost I ended up looking for the answers on most of the challenges. Well, this time around I’m hunting and digging for the answers myself. I really thought i was too stupid to get this stuff.

I’m on my first algorithm challenge, and I was curious if there was a faster way? The shortest distance between two points is a straight line, and that certainly applies to code as well. It also leaves less room for error, so any feedback is welcome. It’s a simple challenge, so be gentle on your feedback :slight_smile:

function reverseString(str) {
  str = str.split("");
  strSplit = str.reverse("");
  join = strSplit.join("");
  return join;
}

reverseString("hello");

I’ve added a spoiler blur to your solution. We like to help campers avoid stumbling across solutions that they aren’t looking for.

just a shorter line

function reverseString(str){
return str.split("").reverse().join("");
}

OR go es6 for one liner

const reverseString = str => str.split("").reverse().join("");

arrow functions still confuse me sometimes but the more i use them the more i like them. they can really cut down the amount of code i need to write and once accustomed to them, i think it makes code more understandable, just reading left to right its like okay we got a string then split ok then reverse that array ok the join again mmk.

Thanks! This time around it’s been much easier. I look at websites all day, and I get discouraged when I’m looking at source and the JavaScript looks like hieroglyphics. When I can apply this stuff I’m sure it will make a lot more sense.