-19
1
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.
1The empty array and a single-element array would probably be good test cases. – Martin Ender – 2016-05-02T17:33:37.457
21
I'm not a huge fan of the very rigid input format. You've chosen one specific way languages denote arrays which gives an arbitrary benefit to all languages using this syntax. Other languages might not use
– Martin Ender – 2016-05-02T17:35:51.293,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.3"Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays" Probably because it's extremely trivial. One byte in both Pyth and Jelly. – Doorknob – 2016-05-02T17:36:19.687
8@Doorknob I don't think simple challenges are a problem. But since they are only interesting in languages which don't have built-ins for them (i.e. esolangs in this case), it's a bit pointless to pose a simple challenge without making it as inclusive for all languages as possible. – Martin Ender – 2016-05-02T17:42:48.223
Do we need to take input as a string, or an array? Some of the specifications you list look like you want strings, but none of the active answers do it that way. – MegaTom – 2016-05-02T18:03:29.843
@Doorknob And it would be one byte in Vitsy, save for the rigid input format. – Addison Crump – 2016-05-02T18:10:18.963
@MartinBüttner Well, that IS the challenge! (replying to very rigid input format comment) – Erik the Outgolfer – 2016-05-03T08:54:05.870
@ΈρικΚωνσταντόπουλος That's also why the challenge is so unpopular: if you want to make a challenge about string processing, make a challenge about string processing. But making a challenge that is seemingly about reversing an array, but then is dominated by string processing in arbitrary set of languages (while it can be solved with a single built-in in languages that get the string processing for free because the format happens to match their syntax), is mostly not in the spirit of this community. – Martin Ender – 2016-05-03T08:57:17.130
@MartinBüttner I have specified that both arrays and strings are allowed. – Erik the Outgolfer – 2016-05-03T09:06:40.780
But we still have the strict output format. – CalculatorFeline – 2016-05-03T14:35:58.460
@CatsAreFluffy I don't see anywhere that we are supposed to output to stdout, even less that there's a strict output format. – Katenkyo – 2016-05-03T14:38:11.210
See the Molecule answer. – CalculatorFeline – 2016-05-03T14:40:32.353
@CatsAreFluffy if this is only in a comment on a submission, you can practically ignore it, as it isn't in the specs – Katenkyo – 2016-05-03T14:43:52.083
@CatsAreFluffy I changed output format, although I didn't like that change at all. – Erik the Outgolfer – 2016-05-12T07:44:02.587