Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions 1.programmers/lv.0/치킨쿠폰.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// https://school.programmers.co.kr/learn/courses/30/lessons/120884

// ver 1. 최초 코드
const 치킨쿠폰 = (chicken: number): number => {
let coupon = 0;
let totalService = 0;
while (chicken > 0) {
coupon += chicken % 10;
totalService += Math.floor(chicken / 10);
chicken = Math.floor(chicken / 10);
if (coupon >= 10) {
totalService += Math.floor(coupon / 10);
chicken += Math.floor(coupon / 10);
coupon = coupon % 10;
}
}
return totalService;
};

// ver 2. 개선 코드
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 간소화 시도


console.log(치킨쿠폰(100)); // 11
console.log(치킨쿠폰(1081)); // 120
console.log(치킨쿠폰(1999)); // 222