코딩테스트 연습
012-부족한 금액 계산하기
__g__
2022. 5. 15. 14:11
function solution(price, money, count) {
let total = 0; // 계산한 price와 count를 담을 변수
for (let i=0; i <= count; i++) { // count만큼 반복
total += price*i; // price는 count만큼 값이 늘어남
};
if (total > money) { // 비용이 내가 가진 돈보다 클 때
return total - money; // 모자란 돈을 반환
} else { // 모자라지 않다면 0 반환
return 0;
}
};