코딩테스트(JavaScript)/코딩테스트 입문
프로그래머스- 분수의 덧셈
paintover23
2023. 7. 20. 17:56
728x90
function solution(numer1, denom1, numer2, denom2) {
var top = numer1 * denom2 + numer2 * denom1
var bottom = denom1 * denom2
var gcdValue = gcd(top, bottom)
return [top /gcdValue, bottom / gcdValue];
}
function gcd(a, b) {
return a % b === 0 ? b : gcd(b, a % b);
}
728x90
반응형