The algorithm discussed in the post reverses a given string using JavaScript.

function reverseString(str) {

//convert the string into an array using split function
var array = str.split(“”);

//reverse the elements in the array using JS reverse function
var revString = array.reverse();

//convert back to string using JS join function
return revString.join(“”);

}

reverseString(“hello”) should become “olleh”.

Reverse a String

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: