2021-10: On the Right Side
Write a function that:
- has a right argument
Tthat is a character scalar, vector or a vector of character vectors/scalars. - has a left argument
Wthat is a positive integer specifying the width of the result. - returns a right-aligned character array
Rof shape((2=|≡T)/≢T),WmeaningRis one of the following:- a
W-wide vector ifTis a simple vector or scalar. - a
W-wide matrix with the same number rows as elements ofTifTis a vector of vectors/scalars.
- a
- if an element of
Thas length greater thanW, truncate it afterWcharacters.
💡 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