Note: This challenge is not the same.
Challenge
Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays (although we've got one for n-dimensional ones)! This should operate only on the 1st dimension, not on all dimensions of an array.
Rules
- Standard loopholes are denied
[[1, 2], [3, 4]]
becomes[[3, 4], [1, 2]]
, not[[4, 3], [2, 1]]
.- This is code-golf, but no answer is accepted. Go beat the others!
- You can get the array any way, except hardcoding. You can also get a string and process it.
- The input will be an array (yes, commas or no commas, it needs to be an array).
Test cases
These are the test cases:
[1, 2, 3, 4]
[1, 2, 'hello', 'world!']
[[1, 2, 3, 4], [2, 3, 4, 1]]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
These are the supposed results:
[4, 3, 2, 1]
['world!', 'hello', 2, 1]
[[2, 3, 4, 1], [1, 2, 3, 4]]
[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
You may accept input as [1 2 3 4]
, or even 1 2 3 4
, or any other form or array your language has.
,
as separators (but only spaces), or use;
instead, and some might use()
or{}
instead of[]
. On top of that, many languages don't support arrays of mixed type, or strings at all. It's normally a good idea to allow people to take the array in the most natural form for their language. \$\endgroup\$