xxxxxxxxxx
function reverseString(str) {
return str.split('').reverse().join('');
}
var originalString = "Hello World!";
var reversedString = reverseString(originalString);
console.log(reversedString); // Output: "!dlroW olleH"
xxxxxxxxxx
function reverseString(s){
return s.split("").reverse().join("");
}
reverseString("Hello");//"olleH"
xxxxxxxxxx
const str = 'JavaScript is awesome';
function reverseAString(str) {
return str.split('').reverse().join('');
}
console.log(`Reversed string is: ${reverseAString(str)}`);
xxxxxxxxxx
function reverseString(s){
return s.split("").reverse().join("");
}
reverseString("Hello");//"olleH"
reverse a string using recursion in js
xxxxxxxxxx
function reverseString(str) {
if (str === "")
return "";
else
return reverseString(str.substr(1)) + str.charAt(0);
}
reverseString("hello");
xxxxxxxxxx
const reverse = str => str.split('').reverse().join('');
reverse('hello world');
// Result: 'dlrow olleh'
xxxxxxxxxx
let a = "foo";
// function for reversing a string
function reverseString(str) {
return str.split("").reverse().join("");
}
console.log(a); // "foo"
let b = reverseString(a);
console.log(b); // "oof"
xxxxxxxxxx
// ideone - Method 1 for reversing a string
function reverseString(str){
strRev = "";
for(let i=0; i<str.length; i++){
strRev = str[i] + strRev;
}
return strRev;
}
console.log(reverseString("Hello"));
xxxxxxxxxx
function reverseString(str) {
return str
.split("")
.reverse()
.join("");
}
xxxxxxxxxx
function reverseString(str) {
let reversed = [];
for (i = str.length - 1; i >= 0; i--) {
reversed.push(str[i]);
}
return reversed.join('');
}