Revision 5e4345e3-6cda-4514-a83c-50ac90f32511 - Code Golf Stack Exchange
# [APL (Dyalog Classic)], 28 bytes
1↓∊((¯2↓⊢),2↑⌽)¨' '(,⊂⍨⊣=,)⍞
`⎕ML` and `⎕IO` are both `1`,
[Try it online!][TIO-jbqlz07e]
[APL (Dyalog Classic)]: https://www.dyalog.com/
[TIO-jbqlz07e]: https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v//Ud/UR20TDB@1TX7U0aWhcWi9EYjZtUhTB8iY@Khnr@ahFeoK6ho6j7qaHvWueNS12FZH81HvvP//g/NzU0syMvPSFYoS81LycxXS81OLFTJSi1IB "APL (Dyalog Classic) – Try It Online"
# Explanation
- **`... (,⊂⍨⊣=,) ...`** Split (while keeping borders, and appending a border to the beginning) ...
- **`... ⍞`** ... the input ...
- **`... ' ' ...`** ... at spaces.
- **`... ( ... )¨ ...`** Then, to each element of that:
- **`... , ...`** Concatenate ...
- **`... (¯2↓⊢) ...`** ... every item except the last two ...
- **`... 2↑⌽ ...`** ... with the reverse of the last two elements.
- **`1↓∊ ...`** Finally, return all but the first element of the flattened result.