REVERSE A STRING

Question : Write a Program to Reverse a String.

Example :

  • word => drow
  • english => hsilgne
  • fun => nuf
  • longest => tsegnol

Method 1

//Using inbuilt funtions
function reverseAString(str) {
let reveresedString = str.split("").reverse().join("")
return reversedString;
}
console.log(reverseAString("hello"));
//Prints: olleh

Method 2

//Without using inbuilt function
function reverseAString(str){
let reversedString="";
for(let i=str.length-1; i>=0; i--){
reversedString += str[i];
}
return reversedString;
}
console.log(reverseAString("hello"));
//Prints: olleh