Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Why is this not done for arrays with variable lengths? First, odd and even arrays have different characteristics; second, only requiring to solve for 1 length instead of all arrays in general makes the problem very boring, and becomes a puzzle rather than a kata.
The tests are unnecessarily obtuse: it doesn't even show what the actual array length or the exchange end result is when the tests fails, which is unacceptable.
time complexity is O(n)
Good kata.
I propose creating an version for 1kyu, by adding "[...]", quantifiers {m,n}, non greedy "*+?", escaping, multiple "or", and lookaheads "(?=...)/(?!...)"
[ab^cd]: new Chars('ab', 'cd')
regex{m,n}: new Times(regex, m, n)
etc
Yes, this is not "code challenge".
Solving this problem is only an idea (in the form of a set of 3*m integers), and it does not matter how it will be framed. The length of the array also has no special meaning. 99 is enough to find the common idea for any odd length, not to use brute force.
To find the solution to this problem, one could try to find it via programming, or maybe find the solution from some sources, but even when programming is used, that code is not the code that will find its way in the solution box.
In essence you are asking for an object literal, and only because that would be a long literal (50 entries) one could decide to shorten the solution text with the use of some kind of loop. But that code is not essential to the kata, and so we cannot really call this a code challenge.
For that reason I do not find this very useful. Solutions don't reveal how the solution was found (if by programming at all).
It would be a bit better (but not much) if this kata asked for the shortest exchange array (without revealing any clues about how short that would be) for any array sizes. That would at least require some programming code to appear in the solution, and you could make your tests dynamic as well (i.e. with random tests).
orderBy
beforeselect
.You can order on things you are not selecting. Any transformation
select
does can be done inorderBy
internally if necessary.This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution