Sort by two keys in four languages.
transcript
A payout report must show the largest payout first. Ties go by name, from A to Z. Write the rule once, and test it on a tie. How does each language say that?
Six merchants are paid these units. Amy and kai both have ninety. Every language must give the same order. The name must break the tie.
Python builds a key tuple. Minus units, then the name. One line, and it reads like the rule. Tuples compare item by item.
Java chains comparators. Compare units, reverse it, then compare names. Each part says one thing about the order. Never subtract two ints.
C plus plus uses a lambda. If units differ, compare units with greater than. The tie test comes after the first key. Otherwise compare the names with less than.
JavaScript returns a number. Subtract the units, high to low. Returning a boolean would break the sort. On a tie, compare the names.
One rule, four syntaxes. Full breakdown in the lecture.