반응형
화살표함수
-
프로그래머스 lv.0 2일차공부/코딩테스트 2023. 1. 12. 20:21
프로그래머스 lv.0 1. 숫자 비교하기 let solution = (num1,num2) => { let answer; if (num1==num2) { answer = 1; } else { answer = -1; } return answer; } 삼항연산자를 사용해서도 처리할 수 있다. function solution(num1, num2) { var answer = num1 === num2 ? 1 : -1; return answer; } *삼항연산자 if ~ else 조건문 대체로 많이 사용 condition ? exprIfTrue : exprIfFalse; 조건문 ? 참일 경우 : 거짓일 경우; //연결된 조건문은 아래 처럼 처리 function example(…) { return condition1 ..