์ฒซ ๋ฒ์งธ ๋ถ์์ ๋ถ์์ ๋ถ๋ชจ๋ฅผ ๋ปํ๋ denum1, num1, ๋ ๋ฒ์งธ ๋ถ์์ ๋ถ์์ ๋ถ๋ชจ๋ฅผ ๋ปํ๋ denum2, num2๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง๋๋ค. ๋ ๋ถ์๋ฅผ ๋ํ ๊ฐ์ ๊ธฐ์ฝ ๋ถ์๋ก ๋ํ๋์ ๋ ๋ถ์์ ๋ถ๋ชจ๋ฅผ ์์๋๋ก ๋ด์ ๋ฐฐ์ด์ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด๋ณด์ธ์.
denum1 | num1 | denum2 | num2 | result |
---|---|---|---|---|
1 | 2 | 3 | 4 | [5, 4] |
9 | 2 | 1 | 3 | [29, 6] |
์ ์ถ๋ ฅ ์ #1
์ ์ถ๋ ฅ ์ #2
function solution(denum1, num1, denum2, num2) {
let a = denum2*num1 + num2*denum1;
let b = num1*num2;
let maximum = 1;
for(let i = 1 ; i <= a ; i ++) {
if(a%i === 0 && b%i === 0) {
maximum = i
}
}
return [a/maximum, b/maximum]
}