Challenge #8 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Challenge #8

Reverse string from left and right to middle ABCDEFGHIJK into DCBAEKJIHGF any programming language are most welcome

25th Nov 2017, 9:37 AM
Amar Dahake
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(""));
25th Nov 2017, 9:42 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 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)); }
25th Nov 2017, 9:51 AM
Dev
Dev - avatar
+ 5
Hmmm, a good place for Python. But can I assume odd length?
25th Nov 2017, 10:39 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar