문제
화면 너비를 첫 번째 인수로, 가로 세로 비율(w:h)을 두 번째 인수로 취하는 JavaScript 함수를 작성해야 합니다. 이 두 입력을 기반으로 함수는 화면 높이를 반환해야 합니다.
예시
다음은 코드입니다 -
const ratio = '18:11';
const width = 2417;
const findHeight = (ratio = '', width = 1) => {
const [w, h] = ratio
.split(':')
.map(Number);
const height = (width * h) / w;
return Math.round(height);
};
console.log(findHeight(ratio, width)); 출력
다음은 콘솔 출력입니다 -
1477