-
[Programmers] JavaScript 알고리즘 | Lv.0 간단한 논리 연산► JS Algorithm/Programmers 2024. 1. 17. 20:53반응형
🔒 문제 설명
boolean 변수 x1, x2, x3, x4가 매개변수로 주어질 때, 다음의 식의 true/false를 return 하는 solution 함수를 작성해 주세요.
- (x1 ∨ x2) ∧ (x3 ∨ x4)
🔒 입출력 예
x1 x2 x3 x4 result false true true true true true false false false false
🔒 입출력 예 설명
입출력 예 #1
- 예제 1번의 x1, x2, x3, x4로 식을 계산하면 다음과 같습니다.
(x1 ∨ x2) ∧ (x3 ∨ x4) ≡ (F ∨ T) ∧ (T ∨ T) ≡ T ∧ T ≡ T
따라서 true를 return 합니다.
입출력 예 #2
- 예제 2번의 x1, x2, x3, x4로 식을 계산하면 다음과 같습니다.
(x1 ∨ x2) ∧ (x3 ∨ x4) ≡ (T ∨ F) ∧ (F ∨ F) ≡ T ∧ F ≡ F
따라서 false를 return 합니다.
- ∨과 ∧의 진리표는 다음과 같습니다.
x y x ∨ y x ∧ y T T T T T F T F F T T F F F F F 🔐 solution of mine
Boolean()
Math.max()
Math.min()
const solution = (x1, x2, x3, x4) => console.log(Boolean(Math.min(Math.max(+x1, +x2), Math.max(+x3, +x4)))); solution(false, true, true, true); // expected output: true solution(true, false, false, false); // expected output: false
🔐 solution of others
논리연산자
const solution = (x1, x2, x3, x4) => console.log((x1 || x2) && (x3 || x4)); solution(false, true, true, true); // expected output: true solution(true, false, false, false); // expected output: false
🔐 solution of others
산술연산자const solution = (x1, x2, x3, x4) => console.log((x1 + x2) * (x3 + x4) ? true : false); solution(false, true, true, true); // expected output: true solution(true, false, false, false); // expected output: false
반응형'► JS Algorithm > Programmers' 카테고리의 다른 글
[Programmers] JavaScript 알고리즘 | Lv.0 홀짝 구분하기 (0) 2024.07.07 [Programmers] JavaScript 알고리즘 | Lv.0 가까운 수 (0) 2024.01.18 [Programmers] JavaScript 알고리즘 | Lv.0 숨어있는 숫자의 덧셈 (2) (0) 2024.01.17 [Programmers] JavaScript 알고리즘 | Lv.0 문자 리스트를 문자열로 변환하기 (0) 2024.01.16 [Programmers] JavaScript 알고리즘 | Lv.0 약수 구하기 (0) 2024.01.16