Skip to content

Instantly share code, notes, and snippets.

@DoonDoony
Created June 6, 2020 04:48
Show Gist options
  • Save DoonDoony/3f604ca7517ecb1d9b3f9e1da4d3f6c9 to your computer and use it in GitHub Desktop.
Save DoonDoony/3f604ca7517ecb1d9b3f9e1da4d3f6c9 to your computer and use it in GitHub Desktop.
const format = new Intl.NumberFormat('en-Us', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
}).format
function formatCurrency(number) {
return format(number)
}
class Play {
amount = 0;
constructor(audience) {
this.audience = audience
}
calculate() {}
getPoint() {
return Math.max(this.audience - 30, 0)
}
}
class Tragedy {
amout = 40000;
constructor(audience) {
super(audience)
}
calculate() {
if (this.audience > 30) {
this.amount += 1000 * (this.audience - 30)
}
return this.amount
}
}
class Codemy {
amount = 30000;
constructor(audience) {
super(audience)
}
calculate() {
if (perf.audience > 20) {
this.amount += 10000 + 500 * (this.audience - 20)
}
this.amount += 300 * this.audience
return this.amount
}
getPoint() {
let value = super.getPoint()
value += Math.floor(this.audience / 5)
return value
}
}
function createPlay(audience, playType) {
if (playType === 'comedy') {
return new Codemy(audience);
} else if (playType === 'tragedy') {
return new Tragedy(audience);
}
throw new Error(`알 수 없는 장르 ${playType}`);
}
function statment(invoice) {
let result = `청구 내역 (고객명: ${inovice.customer})\n`
const data = invoice.performances.map(perf => {
const play = createPlay(perf.audience, perf.playID)
return {
amount: play.calculate(),
credits: play.getPoint(),
}
})
data.forEach() // 출력
data.reduce() // 총액 계산
result += `총액 ${format(totalAmount / 100)}`
result += `적립포인트 ${volumeCredits} \n`
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment