The description should explain that you are expected to throw a NullReferenceException if the array is null.
But was: <System.ArgumentNullException: Value cannot be null.
Thank you (GrahamD) for raising this issue and thank you (JetFly) for providing these example test cases.
I've added them to the kata, with the addition of a couple that require the user to return "1 year".
It seems odd that the distance driven between the last fill up of the month and the first fillup of the next month is not included.
For example if you only fill up on the 1st of three consecutive months and drive 100 miles between filling up by this measurement you will have driven 0 miles each month when in fact you drove 100 miles each month.
tldr: U can't say that table is ordered, or the result is ordered(unless it's specified to order it).
You can always order finite set, as ordering require relation, and it is always possible to make relation between all objects in finite set.
Set of possible relations between elements of finite amount of sets is a carthesian product of those finite amount of sets,
relation is element of this set. In this case, we can simply tell that any result is ordered by relation x1x2...xn-1xn, where x~y means x is in relation with y.
More, ordering in sql makes preassumption that we want order result by '>' relation, or '<' in case of descending.
However, if we don't specify ordering, result of query should be treated as SET, same as tables in database, which means result is always UNORDERED (Disordered? It sounds like it has mental problems :D) unless we specify to order it somehow.
You're right. I'll give it some thought and write some. :)
The line (record) terminator is a carriage-return/line-feed combination. If the list is empty, there are no records (i.e. no lines), so there are no CrLfs to terminate them.
Think about a hypothetical process which is going to take your output as input and interpret it. The first thing it's (probably) going to do is check if the input is empty. If so, it will know there are no records. If not (and if it contains a CrLf, that counts as "not empty"), it's going to try and extract records from it.
Makes perfect sense to me, and I work with stuff like this all the time: each record must be terminated by a carriage-return/line-feed combination (in fact I often work with requirements where the record terminator is a | or something, meaning it's actually one continuous line in the file, but I digress). If there are no records, there are no record terminators.
Maybe I should just update the description to make it clearer. :)
Needs random tests
Okay, so every non-empty input has a trailing \r\n.
But then empty string does not have it?
I don't think these two are consistent with each other.
I tend to agree with some of the other comments: this solution works for small arr arrays. As the length of arr increases this would become much less efficient (I think O(n^2)?). The other solutions are using a dictionary to overcome this possible bottleneck, since a dictionary is implemented as a hash table.
Good solution overall though. The counting of the occurrences is the only thing I would change.
Acording to experience, I would leave it there as some code I encounter are not optimally written and leave it to programmer to solve it in such a way that doesnt break the SOLID principle.
But thats only a suggestion.
Thanks for the suggestion! I'll give it some thought. :)
This comment is hidden because it contains spoiler information about the solution
What a pity I can't upvote more than once. What an awesome post! myjinxin2015, you just made my day. :-)
As usual, my English grammar is always terrible. :(
So I'm willing to accept all the suggestions for improving English grammar. ^_^
As you said, I want to keep the neat x and y format. :]
如你所言，我想要保持整洁的 x and y 格式。[迷之微笑]
So I decided to take your last suggestion: material7 or material8(at least one, or both) must be selected :)
Apologize to the 160 warriors who were misled by my description(even though they finally got the right answer ;-))
the neat x and y format
material7 or material8(at least one, or both) must be selected
The above statements were generated by language translation software. If there is grammatical error, I do not bear any legal responsibility. :D
If there is any ambiguity, please use Chinese semantics as the standard. :P
I reserve the final right to interpret the Chinese text. :)