Perl / JavaScript, 7473 bytes
Perl returns a palindrome and JavaScript 'de-palindromizes' the input string.
s=prompt();console.log(s.slice(0,-s.length/2+.5|02));eg=1;t=eg;s=$=reverse$_=eg
JavaScript
Assumes the string is a valid palindrome already.
All the work happens in the first section:
s=prompt();console.log(s.slice(0,-s.length/2+.5|02));
Stores input in s
, then returns the first half (rounded-up) of the string. The rest of the script is pointless variable assignments:
eg=1;t=eg;s=$=reverse$_=eg
Try it here:
s=prompt();console.log(s.slice(0,-s.length/2+.5|02));eg=1;t=eg;s=$=reverse$_=eg
Perl
Must be run with -pl
, eg:
perl -ple 's=prompt();console.log(s.slice(0,-s.length/2+.5|02));eg=1;t=eg;s=$=reverse$_=eg' <<< 'test'
# returns testtset
The code is basically two substitutions (s///
), but using =
as the delimiter instead of /
:
s/prompt();console.log(s.slice(0,-s.length\/2+.5|02));eg/1;t/eg;s/$/reverse$_/eg
The first, replacing prompt();console.log(s.slice(0,-s.length\/2+.5|02));eg
(which, admittedly will mess up your palindrome thatstring if it contains something like "prompt;console.logs.slice0;eg"slice0,-s.length/2;eg"
...) with 1;t
which is eval
ed, returning t
, the second replaces the end of the string ($
) with reverse$_
which is then also eval
ed and appends the original source string reversed.