Sorting objects by multiple fields
TypeScript
Medium
sorting
Task «Sorting objects by multiple fields»
Write a program that takes a list of objects with fields name (string) and age (number). Sort the list first by age in ascending order, and for the same age — alphabetically by name in ascending order. Output the sorted objects in the format "name age" one per line. It is guaranteed that the number of objects does not exceed 1000, and the length of name is no more than 50 characters.
Input Format
The first line contains an integer n (1 ≤ n ≤ 1000) — the number of objects. Then, in each of the n lines, name (a string without spaces) and age (an integer from 0 to 120) are given separated by a space.
Output Format
Output n lines, each in the format "name age", where the objects are sorted by age (ascending), and for equal ages — by name (alphabetical order).
Examples
Example 1
INPUT
4
Zara 22
Anna 22
Bob 21
Eve 23
OUTPUT
Bob 21
Anna 22
Zara 22
Eve 23
Example 2
INPUT
2024-03-04
OUTPUT
Понедельник
main.ts