function solution(n, m) {
const [s, b] = [n, m].sort();
const gcd = getGcd(s, b);
return [gcd, (s * b) / gcd];
}
function getGcd(a, b) {
if (b % a === 0) {
return a;
}
return getGcd(b % a, a);
}
//refactoring
function solution(n, m) {
const [s, b] = [n, m].sort();
const getGcd = (a, b) => (b % a ? getGcd(b % a, a) : a);
const gcd = getGcd(s, b);
return [gcd, (s * b) / gcd];
}
Level
프로그래머스 Lv1
Recruitment