iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 20
1
const getDiscountPrice = (amount, couponCode) => {
  switch (couponCode) {
    case 'DIJFNC':
      return amount * 0.8
    case 'XPFJVM':
      return amount * 0.75
    case 'FJDPCX':
      return amount * 0.5
    default:
      return amount * 1
  }
}
const getDiscountPrice = (amount, couponCode) => {
  let discount = 1
  if (couponCode === 'DIJFNC') discount = 0.8
  if (couponCode === 'XPFJVM') discount = 0.75
  if (couponCode === 'FJDPCX') discount = 0.5
  return amount * discount
}
const discountMultiplier = {
    'DIJFNC': 0.8,
    'XPFJVM': 0.75,
    'FJDPCX': 0.5
}
const getDiscountPrice = (amount, couponCode) => amount * discountMultiplier[couponCode]

參考資料

4 Things You Have to Unlearn to Become a Better Programmer


上一篇
React:Suspense
下一篇
Code-Splitting in React
系列文
那些我還沒深入理解就開始使用的東西30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言