[Programmers] 점의 위치 구하기

Heechang Jeong·2023년 3월 15일
0

programmers

목록 보기
5/11
post-thumbnail

🎯 나의 풀이

function solution(dot) {

    if(dot[0] > 0 && dot[1] > 0) {
        return 1;
    } else if(dot[0] < 0 && dot[1] > 0) {
        return 2;
    } else if(dot[0] < 0 && dot[1] < 0) {
        return 3;
    } else return 4;

}


📌 또 다른 풀이

  • 구조 분해를 이용한 풀이

function solution(dot) {
    const [num,num2] = dot;
    const check = num * num2 > 0;
    return num > 0 ? (check ? 1 : 4) : (check ? 3 : 2);
}


Reference

0개의 댓글