2020-1: Let's Split!
Write a function that, given a right argument Y
which is a scalar or a non-empty vector and a left argument X
which is a single non-zero integer so that its absolute value is less or equal to ≢Y
, splits Y
into a vector of two vectors according to X
, as follows:
- If X>0
, the first vector contains the first X
elements of Y
and the second vector contains the remaining elements.
- If X<0
, the second vector contains the last |X
elements of Y
and the first vector contains the remaining elements.
💡 Hint: The Take function X↑Y
might be useful for this problem.
Examples:
9 (your_function) 'SplittingHairs' ⍝ using ]Boxing on
┌─────────┬─────┐
│Splitting│Hairs│
└─────────┴─────┘
¯3 (your_function) 'DyalogAPL'
┌──────┬───┐
│Dyalog│APL│
└──────┴───┘
10 (your_function) ⍳10
┌────────────────────┬┐
│1 2 3 4 5 6 7 8 9 10││
└────────────────────┴┘
1 (your_function) 'works' 'with' 'words' 'also'
┌───────┬─────────────────┐
│┌─────┐│┌────┬─────┬────┐│
││works│││with│words│also││
│└─────┘│└────┴─────┴────┘│
└───────┴─────────────────┘
your_function ←
Solutions

