Ad
  • Custom User Avatar

    It's like saying that . is used for full-stops and shouldn't be used for dot balls in this kata. So just think I'm re-inventing the > symbol.

  • Custom User Avatar

    Yes, unsuprisingly the > symbol does indeed mean "greater than." Combined with this sentence from the description:

    Given the entire Solar System in the form of a list. Return a new list which has either '<', '>' or '=' depending on whether the planet is smaller than the planet on its left or not.
    

    It's pretty clear to see that > means "This planet is greater than the one on its left"

    We're always use this symbol as index from bigger object to smaller. From. bigger. to. smaller. object

    And it's no different in this case. No. Different. In. This. Case. Mercury > Asteroid Learn this please.

  • Custom User Avatar

    "So for a list like ["Asteroid", "Mercury"], the resulting array [">"] means "Mercury is greater than the item on the left","

    Bro, stop it, please. We're always use this symbol as index from bigger object to smaller. From. bigger. to. smaller. object. Learn this please.

    This kata required inverted result. Period.

  • Custom User Avatar

    It would be better if you write Arrays.sort(array); outside the for loop, since by doing that you are essentially sorting array each time while traversing it, which is redundant.

    Also as a best practice, you can declare a variable like int len = array.length; (basically precompute the array's length), and use that precomputed length in the for loop, like for (int i = 0; i < len; i++)

  • Custom User Avatar

    It makes more sense when you consider that the return value is an array which represents the relative size of each planet compared to the one on its left. So for a list like ["Asteroid", "Mercury"], the resulting array [">"] means "Mercury is greater than the item on the left", which is why the greater than symbol is used. In the end, though, I don't think one way is less confusing than the other. Your list of pairs to compare could easily be reversed: Asteroid and Mars, Venus and Asteroid, Jupiter and Venus, Asteroid and Jupiter, Earth and Asteroid, Pluto and Earth. -- they are the exact same comparisons, but now the greater/less than signs are reversed. I think it only makes more sense to you in the way that you described because your list of comparisons exactly follows the order of the items in the original array.

  • Custom User Avatar

    In my humble opinion, the condition for comparison the result is reversed.

    The correct order of planets is: Asteroid < Pluto < Mercury < Mars < Venus < Earth < Neptune < Uranus < Saturn < Jupiter.

    Based on this, if we have a list of planets like:

    ["Mars", "Asteroid", "Venus", "Jupiter", "Asteroid", "Earth", "Pluto"]

    We would compare the following pairs:
    Mars and Asteroid, Asteroid and Venus, Venus and Jupiter, Jupiter and Asteroid, Asteroid and Earth, Earth and Pluto.

    When we compare each entry, such as Mars and Asteroid, we expect the result to be '>' because Mars is bigger than Asteroid.
    Similarly, Venus and Jupiter should result in '<', because Venus is smaller than Jupiter.

    However, the question demands the reverse—meaning we should return '<' when the left planet is bigger, and '>' when it's smaller. This inversion of logic is what makes the current condition incorrect, and due to this we need to write the opposite condition in comaparison like -

    return orderOne == orderTwo ? EQUAL : (orderOne > orderTwo ? SMALLER : GREATER);

    when it actually should be -

    return orderOne == orderTwo ? EQUAL : (orderOne < orderTwo ? SMALLER : GREATER);