6 kyu

Alternating sort

Description
Loading description...
Algorithms
Arrays
Sorting
  • Please sign in or sign up to leave a comment.
  • o2001 Avatar

    JavaScript Translation. Modifies the description to make it language agnostic.

    • Side note: unless I'm missing something, the Python tests seem to care about the parity of the array length - isn't that an irrelevant attribute? The ratio of negatives to positives is, imo, the key attribute. The parity affects nothing - you're not dividing by 2. So for the fixed tests, I did not group things by parity like the Python version.
    • hobovsky Avatar

      Parity can be relevant for solutions which try to process the input in chunks of 2 elements and risk miscalculating the end, skip the last element or run into out of bounds access.

      or maybe solutions which try to split some array in half and get it wrong on odd lengths.

    • o2001 Avatar

      Oh makes sense. Either case the random tests guarantee both odd and even lengths

  • ahmet_popaj Avatar

    Very nice kata to figure out, great.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • Blind4Basics Avatar

    input is vulnerable to mutation, in the random tests

  • StefanPochmann Avatar

    Your tests never include duplicate values. Better test that as well.

  • StefanPochmann Avatar

    Got this:

    Random test for even array length: [-669, 0, -1088, 89, -2807, 1135, -2979, 2269, -4103, 2337, -5255, 2539, -6052, 3146, -7453, 3346, -8122, 5012, -8164, 5113, -9240, 5434, 6557, 7928, 8017, 8407, 9034, 9091, 9528, 9568]
    should equal [-669, 89, -1088, 1135, -2807, 2269, -2979, 2337, -4103, 2539, -5255, 3146, -6052, 3346, -7453, 5012, -8122, 5113, -8164, 5434, -9240, 6557, 7928, 8017, 8407, 9034, 9091, 9528, 9568]
    

    I'm sure you confused mine and yours. My solution definitely doesn't include zeros. Because I do what the problem asks, output only negative and positive values.

    • Blind4Basics Avatar

      yes, expected and actual are effectively swapped in the random tests. And 0 can show up from time to time in some of those.

    • barghest Avatar

      Adapted the description to include "non-negative" values and fixed test cases. Thanks!

      Issue marked resolved by barghest 7 years ago
  • Blind4Basics Avatar

    Hi,

    Interesting one. You should add some edge cases, though:

    • only negative values
    • only positive values
    • same as your last fixed tests, but with extra negative values
    • barghest Avatar

      Thanks, I've added fixed tests that account for all three of these cases as well as random tests for "only negative" and "only positive" arrays.

      Issue marked resolved by barghest 7 years ago
    • Blind4Basics Avatar

      Ah, I forgot one important edge case: what about 0? => you have to tell if you considere it positive or negative (positive, looking at your solution) and put some tests with it. Note that your random tests may not generate any zero, otherwise, ZED's solution would never have passed.

    • Blind4Basics Avatar

      This comment has been hidden.

    • StefanPochmann Avatar

      Zero isn't positive or negative and shouldn't be "considered" as such. The judge solution uses >= 0, so the kata should say "non-negative" instead of "positive".

    • Blind4Basics Avatar

      that would depend on who you are talking too, unfortunately. That's why it should be told plainly in the description.