xxxxxxxxxx
def reverse(string):
string = "".join(reversed(string))
return string
s = "SoftHunt"
print ("The original string is : ",end="")
print (s)
print ("The reversed string(using reversed) is : ",end="")
print (reverse(s))
xxxxxxxxxx
const reverse = str => str.split('').reverse().join('');
reverse('hello world');
// Result: 'dlrow olleh'
xxxxxxxxxx
const reverseString = (str) => {
const revArray = [];
const length = str.length - 1;
// Looping from the end
for(let i = length; i >= 0; i--) {
revArray.push(str[i]);
}
// Joining the array elements
return revArray.join('');
}
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
xxxxxxxxxx
function reverseString(str) {
let reversedStr = "";
for (let i = str.length - 1; i >= 0; i--) {
reversedStr += str[i];
}
return reversedStr;
}
xxxxxxxxxx
const stringReverse = str => str.split("").reverse().join("");
stringReverse("Welcome to Javascript")
//tpircsavaJ ot emocleW
xxxxxxxxxx
sentence = "This is just a test"
reversed = sentence[::-1]
print(reversed)
xxxxxxxxxx
function reverseString(str) {
return str.split('').reverse().join('');
}
reverseString('string'); // "gnirts"
xxxxxxxxxx
// Reverse string
function reverseString(str) {
let reverseStr = '';
let i = str.length - 1;
while (i >= 0) {
reverseStr += str[i];
console.log(reverseStr);
i--;
}
return reverseStr;
}
reverseString('hello');
// OR
function reverseString(str) {
for (var reversedStr = '', i = str.length - 1; i >= 0; i--) {
reversedStr += str[i];
}
return reversedStr;
}
// OR
function reverseString(str( {
result = ""
for (i = 0; i < str.length; i++) {
result = str[i] + result
}
return result
}
// OR
function reverseString(str) {
return str.split('').reverse().join('');
}
xxxxxxxxxx
static string reverseString(string str){
string output = "";
int length = str.Length-1;
for (int i = 0; i < length+1; i++)
{
output += str[length - i];
}
return output;
}
xxxxxxxxxx
class Reverse
{
// Complete the function
// str: input string
public static String reverseWord(String str)
{
String rev = new String();
for(int i = str.length()-1; i>=0; i--){
rev += str.charAt(i);
}
return rev;
// Reverse the string str
}
}
xxxxxxxxxx
def reverse(string):
string = "".join(reversed(string))
return string
s = "SoftHunt"
print ("The original string is : ",end="")
print (s)
print ("The reversed string(using reversed) is : ",end="")
print (reverse(s))