Coordinate Alignment

Problem

Given N coordinates on a plane (x, y), write a program that sorts all coordinates in ascending order.
The sort criterion is first sorted by the x value, and if the x value is the same, it is sorted by the y value.

input

  • The first line is given the number of coordinates N (3<=N<=100,000)
  • Starting from the second line, N coordinates are given in x, y order. Only positive numbers are entered for x and y values
5

2 7
1 3
1 2
2 5
3 6

output

Sort and output N coordinates.

1 2
1 3
2 5
2 7
3 6

Solution

function solution(arr) {
	let answer = arr;

	answer.sort(([a1, a2], [b1, b2]) => a1 - b1 || a2 - b2);

	return answer;
}
function solution(arr) {
	let answer = arr;

	answer.sort((a, b) => {
		if (a[0] === b[0]) return a[1] - b[1];
		else return a[0] - b[0];
	});

	return answer;
}