Reverse an ASCII string
Your goal is to reverse an ascii string. Given a (optionally newline or null terminated) input, output your input in reverse order, optionally followed by a newline. Terminate afterward. Function answers will not be given a newline, and are not expected to output one unless they print the answer to console.
Examples
Assume all inputs are followed by a newline, and are all standard ASCII encoded.
abcdef
-> fedcba
Hello, World!
-> !dlroW ,olleH
racecar
-> racecar
Example program
function solution(x) {
return x.split("").reverse().join("");
}
Further clarifications
- No, you don't have to handle nulls correctly.
- Nor empty inputs.
[Brain-Flak], 12 bytes …
4y ago
[Ahead], 3 bytes SW@ …
4y ago
[C (gcc)], 34 bytes …
4y ago
JavaScript, 25 24 bytes -1 …
3y ago
jq, 16 bytes, preferably `-rR` …
3y ago
C, 66 59 bytes -7 bytes tha …
4y ago
[Python 3], 20 bytes …
3y ago
[Shakespeare Programming Langu …
4y ago
C (gcc), 62 bytes main( …
3y ago
Japt, 1 byte w Uh... …
4y ago
Turing Machine.io, 363 bytes …
3y ago
[PowerShell], 43 bytes …
3y ago
Scala, 9 bytes ```scala .rev …
3y ago
[Perl 5] `-p`, 10 bytes …
3y ago
[Ruby], 14 bytes -> …
4y ago
Laser, 9 bytes ``` c⌜ps …
4y ago
[Haskell], 7 bytes …
3y ago
[Sclipting], (UTF-16) 2 bytes …
3y ago
[Lua], 32 bytes pri …
3y ago
[Bash], 3 bytes rev …
4y ago
Befunge-98, 45 39 37 33 29 21 …
4y ago
Python, 16 bytes ```python …
1y ago
J, 2 bytes ```J |. ``` …
3y ago
[shortC], 24 bytes f(Cs …
3y ago
Rockstar, 67 bytes list …
3y ago
[PHP], 32 24 bytes …
3y ago
[AWK], 48 bytes ORS=""; …
7mo ago
Standard ML, 23 bytes i …
1y ago
R, 32 bytes ```r \(s)intTo …
1y ago
R + magrittr, 31 bytes …
1y ago
Brainfuck, 10 Bytes ```,[ …
1y ago
SOS, 76 bytes +>+>????? …
2y ago
[Java (JDK)], 88 83 bytes …
3y ago
33 answers
Befunge-98, 45 39 37 33 29 21 bytes
v:~<
>a-|
>v$<
,:
^_@
This answer probably sucks :P
Rockstar, 67 bytes
listen to S
split S
O's""
while S
roll S into C
let O be C+O
say O
Try it here (Code will need to be pasted in)
0 comment threads
shortC, 24 bytes
f(C*s){*s&&f(s+1)^P*s);}
A shortC conversion of @Sisyphus's C (gcc) implementation.
0 comment threads
Brainfuck, 10 Bytes
,[>,]<[.<]
Requires EOF to be 0.
,[>,]<[.<]
, # Read character
[ ] # loop as long as current cell is not 0 (EOF)
>, # read and fill the tape to the right with the read characters
< # go back to the last valid character, i.e. one before EOF
[ ] # loop till current cell is 0 (i.e. cell pointer is before the first read character
.< # output character and move left
0 comment threads
Java (JDK), 88 83 bytes
static void f(String s){for(int i=s.length();i>0;System.out.print(s.charAt(--i)));}
0 comment threads
- ← Previous
- 1
- 2
- Next →
1 comment thread