1function reverseString(s){
2 return s.split("").reverse().join("");
3}
4reverseString("Hello");//"olleH"
1function reverseString(str) {
2 return str.split('').reverse().join('');
3}
4
5reverseString('string'); // "gnirts"
6
1//////////////////////////////////////
2function reverse(str) {
3 if(!str || str.length<2 || typeof str !== 'string'){
4 return 'hmmm that is not good...';
5 }
6 return str.split('').reverse().join('');
7}
8
9//////////////////////////////////////
10function reverse(str) {
11 let n = str.length;
12 let s = '';
13 for (let i = n - 1; i >= 0; i--) {
14 s += str[i];
15 }
16 console.log(s);
17}
18reverse('Hello'); // olleH
1public static String reverse(String orig)
2{
3 char[] s = orig.toCharArray();
4 int n = s.length;
5 int halfLength = n / 2;
6 for (int i=0; i<halfLength; i++)
7 {
8 char temp = s[i];
9 s[i] = s[n-1-i];
10 s[n-1-i] = temp;
11 }
12 return new String(s);
13}
14
1String -- Reverse
2Write a return method that can reverse String
3Ex: Reverse("ABCD"); ==> DCBA
4
5USING CORE JAVA
6public static String StrReverse(String str) {
7String reverse="";
8for(int i=str.length()-1; i >= 0; i--)
9reverse += str.toCharArray()[i];
10
11return reverse;
12}
13
14USING STRING BUFFER/BUILDER
15public static String Reverse(String str) {
16return new StringBuffer(str).reverse().toString();
17}