2021-10: On the Right Side
Write a function that:
- has a right argument
T
that is a character scalar, vector or a vector of character vectors/scalars. - has a left argument
W
that is a positive integer specifying the width of the result. - returns a right-aligned character array
R
of shape((2=|≡T)/≢T),W
meaningR
is one of the following:- a
W
-wide vector ifT
is a simple vector or scalar. - a
W
-wide matrix with the same number rows as elements ofT
ifT
is a vector of vectors/scalars.
- a
- if an element of
T
has length greater thanW
, truncate it afterW
characters.
💡 Hint: Your solution might make use of take X ↑ Y.
Examples:
In these examples, ⍴⎕←
is inserted to display first the result and then its shape.
⍴⎕←6 (your_function) '⍒'
⍒
6
⍴⎕←8 (your_function) 'K' 'E' 'Iverson'
K
E
Iverson
3 8
⍴⎕←10 (your_function) 'Parade'
Parade
10
⍴⎕←8 (your_function) 'Longer Phrase' 'APL' 'Parade'
r Phrase
APL
Parade
3 8
starsForSpaces←'*'@(=∘' ')
starsForSpaces 6 (your_function) '⍒'
*****⍒
your_function ←
Solutions

