+ 1

How can i output the reverse of my input

Help

20th Feb 2020, 4:26 AM
Kodjo
Kodjo - avatar
4 Answers
+ 3
#In C++ you can use `reverse` function from <algorithm> ``` std::string s="reverseit"; std::reverse(s.begin(),s.end()); cout<<s; ``` #In HTML you can use <bdo> tag with dir attribute set to "rtl" ``` <bdo dir ="rtl"> reverseit </bdo> ``` #In javascript String doesn't have built in reverse method but Arrays have it. so you can convert string to array ,then reverse it and finally join elements of array to form a String. ``` let str = "reverseit"; str = [...str].reverse(); str = str.join(''); ``` Another way to convert string to charecter array is to use Arryay.from() method. what I have previously used is spread syntax from es6. Refrain from using `split('')` method of string to convert string to charecter array because it doesn't insure unicode charecters will be splited properly.
20th Feb 2020, 4:50 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
+ 1
There is no direct way to print the input in reverse order. You have to reverse the array/string first and then print it(as shown by BroFar )
20th Feb 2020, 4:48 AM
Arsenic
Arsenic - avatar