+ 15
[ASSIGNMENT] Reverse String🚩🚩
Task: take input from user. Then, reverse it using any method. Example: input: solo output: olos input: say output: yas You can use any language to perform this task. I already submitted this challenge to Lesson Factory. https://code.sololearn.com/cpAv2CZejx67/?ref=app
27 Answers
+ 24
https://code.sololearn.com/c3luPGo2uDq3/?ref=app
+ 24
<!-- My try in PHP ✌️👍 😎
Unfortunately can't take user input
(1 Liner) 😉😉😉 -->
<?php
$str = "solo";
echo "Input : $str<br>"."Output: ".strrev($str);
?>
+ 23
Muhammad Khairul Amirin Bin Yaacob
😀😁😄👍Thank you very much, 😆🤗
I'm really honored, surprised and delighted!! 😀😁😄🤘
I'm glad you like my answer and I'm thrilled that you have chosen my answer
for The Best! ☺😆😊
Thanks a lot 😉👍
+ 11
Python -
print(input()[::-1])
JS -
document.write(prompt().split("").reverse().join(""))
+ 9
Three line in ruby:
https://code.sololearn.com/cgJlrvTdTomv/?ref=app
+ 8
one liner in js
console.log(prompt("Enter any word").split("").reverse().join(""));
+ 7
oneliner in python
print(input()[::-1])
https://code.sololearn.com/cz0c0WkSPldd/?ref=app
+ 7
Nice Game ;-)
Functional programming!
Use spread operator ES6
function reverseString(s){ return [...s].reverse().join("");}
Use arrow functions and reduce in ES6
function reverseString(s){ return [...s].reduceRight( (prev, curr) => prev + curr );}
Use ES6 Ternery operator and recursion
function reverseString(s){return (s === '') ? '' : reverseString(s.substr(1)) + s.charAt(0);
}
+ 7
Very simple code in Ruby
https://code.sololearn.com/cS6sl3iQPJqz/?ref=app
+ 6
There is more than one way to do this:
https://code.sololearn.com/c0NFcB1dD5Yu/?ref=app
+ 6
Here it is in JS
https://code.sololearn.com/W5twGmh0scL2/?ref=app
+ 5
+ 5
Just use string method reverse().
+ 4
In C++, just use std::reverse to do the work for you.
+ 4
My try in Java.
https://code.sololearn.com/c2MRxBHAKAbX/?ref=app
+ 4
one liner in python:
print (input ()[::-1])
+ 4
mitali jadhavrao In JS.
+ 3
python code for reverse of string
https://code.sololearn.com/cN964QIsKZUH/?ref=app