Ad
  • 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);