+ 2
Challenge #8
Reverse string from left and right to middle ABCDEFGHIJK into DCBAEKJIHGF any programming language are most welcome
3 Answers
+ 12
ES6 (for odd length inputs):
var s = prompt(""), m = (s.length - 1) / 2;
alert(s.split("").slice(0, m).reverse().join("") + s.charAt(m) + s.split("").slice(m + 1).reverse().join(""));
+ 11
// Lol getting messed up with Java
String str = "ABCDEFGHIJK";
int count = str.length();
String midValue = "";
if(count % 2 == 0) {
midValue = str.charAt((count/2) - 1) + str.charAt(count/2) + "";
} else {
midValue = str.charAt(count / 2) + "";
}
for(int i = str.indexOf(midValue)-1; i >= 0; i--) {
System.out.print(str.charAt(i));
}
for(int i = count - 1; i >= str.indexOf(midValue); i--) {
System.out.print(str.charAt(i));
}
+ 5
Hmmm, a good place for Python.
But can I assume odd length?