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.
5
2 7
1 3
1 2
2 5
3 6
Sort and output N coordinates.
1 2
1 3
2 5
2 7
3 6
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;
}