Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero digits.
Examples:
1) n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3
2) n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6
3) n = 100, x = 5, y = 3 => false because 100 is not divisible by 3
4) n = 12, x = 7, y = 5 => false because 12 is neither divisible
function isDivisible(n, x, y) {
if (n % x === 0) {
if (n % y === 0)
return true
return false
}
return false
}
or
function isDivisible(n, x, y) {
return (n % x !== 0) ? false : (n % y !== 0) ? false : true
}
갑자기 휴파님의 삼항연산자 강조가 떠올라서 저렇게 풀어보았다. 가독성이 조금 떨어지나.🧐 보니까 쉽게 생각하면 쉽게 풀 수 있는 문제였다. 쉽게 접근하려는 노력이 필요하다!
function isDivisible(n, x, y) {
return n % x === 0 && n % y === 0
}