좌표 정렬

WooBuntu·2021년 3월 29일
0

JS 90제

목록 보기
32/33
  • 강의 듣기 전 풀이
function solution(coordinates) {
  return coordinates.sort(([xOfFormer, yOfFormer], [xOfLatter, yOfLatter]) => {
    if (xOfFormer == xOfLatter) {
      return yOfFormer < yOfLatter ? -1 : 1;
    }
    return xOfFormer < xOfLatter ? -1 : 1;
  });
}

const result = solution([
  [2, 7],
  [1, 3],
  [1, 2],
  [2, 5],
  [3, 6],
]);

console.log(result);

0개의 댓글