function solution(brown, yellow) {
var answer = [];
const total = brown + yellow;
let y = 0;
for (let x = Math.floor(Math.sqrt(total)); x <= total; x++) {
if (total % x === 0) {
y = total / x;
if (2 * x + 2 * y - 4 === brown) return y > x ? [y, x] : [x, y];
}
}
return answer;
}
Level
프로그래머스 Lv2