In this challenge, you will be given a text block, and you need to perform reflection on the text.
Input:
- A string to be reflected. The text may not be supplied as an array whose elements are the lines of text. For example,
"ab\ncd"
and['a','b','\n','c','d']
are allowed, but['ab','cd']
or[['a','b'],['c','d']]
are not. You can assume that all of the lines have the same number of characters (padded with whitespace where needed). - A boolean where
True
indicates Y reflection andFalse
indicates X reflection
The two inputs can be passed in any order.
Output:
The reflected string. The characters do not change, only their position. The resulting image block should be aligned to the top left (the first row and column must each contain a non-whitespace character). Trailing whitespace (on any of the lines) is allowed.
Test cases:
False
o /
--|/
|
/ \
/ o
/|--
|
\ /
True
o /
--|/
|
/ \
/ \
|
--|/
o /
True
text
text
False
text
txet
True
P
P
C
G
G
C
P
P
False
P
P
C
G
P
P
C
G
True
abcde
fghij
kl mn
opqrs
tuvwx
tuvwx
opqrs
kl mn
fghij
abcde
This is a code-golf, so answer with the shortest answer in your favorite language!
1
and0
) or we must useTrue
andFalse
? \$\endgroup\$\n
I would go as far as to say that it's not a string representation. \$\endgroup\$