Reverse String

I think it would be wise to start with something simple for the first entry. Why not start with a bit of string manipulation?

The Ask: When a function is called with a string as it's input, The output should be the Reverse String.

Tips and Hints:

Your function should start off like this...

function reverse(str){
return str;
}

// Tests for Function:

// reverse("Hello")

// reverse("Orange")

// reverse("Simone")

Keep in mind that there are multiple solutions for this problem, none of which are incorrect.

Solution #1:

This first solution is worth noting but, will likely get rejected in an interview setting. By using simple ES6 methods, we can skip the traditional approach to this solution.

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

// Tests for Function:

// reverse("Hello") === olleH

// reverse("Orange") === egnarO

// reverse("Simone") === enomiS

Solution #2:

This solution is the preferred approach. It indicates a understanding of the algorithm itself. It uses both a decrementing forloop and concatenation.

function reverse(str) {
let reversed = ' ';
for (let i = str.length - 1; i >= 0; i--) {
reversed+=str[i];
}
return reversed;
}

// Tests for Function:

// reverse("Hello") === olleH

// reverse("Orange") === egnarO

// reverse("Simone") === enomiS