Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar
  • Default User Avatar

    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

  • Default User Avatar

    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.

  • Default User Avatar

    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).

  • Custom User Avatar

    orderBy before select.

    You can order on things you are not selecting. Any transformation select does can be done in orderBy internally if necessary.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    orderBy should be called after select, or vice versa?

    query().select(sel).from([1, 2, 3]).orderBy(ord).execute(ord);
    
    function sel(num) {
      return {n: num};
    }
    
    function ord(a, b) {
      // a, b - numbers, or objects?
    }