重构

  • q7_417989
    了解作者
  • 1.1MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-28 03:45
    上传日期
重构
refactoring-master.zip
  • refactoring-master
  • screenshots
  • 3.refactor_volume_credits.png
    231.9KB
  • 2.query_replace_temp_var.png
    276.5KB
  • 4.change_format_function_delaration.png
    297.2KB
  • 6.query_replace_temp_var.png
    35.1KB
  • 1.refactor_switch.png
    280.7KB
  • .DS_Store
    6KB
  • invoices.json
    297B
  • plays.json
    225B
  • .gitignore
    5B
  • index.js
    2.3KB
  • package.json
    225B
内容介绍
const invoices = require("./invoices.json"); const plays = require("./plays.json"); function statement(invoice, plays) { let result = `Statement for ${invoice.custom}\n`; for (let perf of invoice.performances) { const play = playFor(perf); let thisAmount = amountFor(play, perf); result += ` ${play.name}: ${formatAsUSD(thisAmount / 100)} ${perf.audience } seats \n`; } result += `Amount owed is ${formatAsUSD(totalAmount() / 100)}\n`; result += `You earned ${totalVolumnCredits()} creadits\n`; return result; function totalAmount() { let result = 0; for (let perf of invoice.performances) { const play = playFor(perf); let thisAmount = amountFor(play, perf); result += thisAmount; } return result; } function totalVolumnCredits() { let result = 0; for (let perf of invoice.performances) { result += volumnCreditsFor(perf); } return result; } function formatAsUSD(number) { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", minimumFractionDigits: 2, }).format(number); } function playFor(performance) { return plays[performance.playID]; } function amountFor(play, perf) { let result = 0; switch (play.type) { case "悲剧": result = 40000; if (perf.audience > 30) { result += 1000 * (perf.audience - 30); } break; case "喜剧": result = 30000; if (perf.audience > 20) { result += 10000 + 500 * (perf.audience - 20); } result += 300 * perf.audience; break; default: throw new Error(`unknown type: ${play.type}`); } return result; } function volumnCreditsFor(perf) { let result = 0; const play = playFor(perf); result += Math.max(perf.audience - 30, 0); if ("comedy" === play.type) result += Math.floor(perf.audience / 5); return result; } } const stats = statement(invoices[0], plays); console.log(stats);
评论
    相关推荐
    • IBM重构
      俗话说流程决定绩效,而这一款整理发布的IBM重构定能给你最好的流程参考,欢迎大家下载IBM重构...该文档为IBM重构,是一份很不错的参考资料,具有较高参考价值,感兴趣的可以下载看看
    • 代码重构
      代码重构
    • ATM重构
      自动柜员机
    • 代码重构
      代码重构入门代码
    • 重构章鱼
      重构章鱼
    • 代码重构
      代码重构
    • 代码重构
      代码重构
    • 重构示例
      重构示例 자바,“코드를다다양한”-리플렉션API(클래스정보조회)
    • 重构
      重构
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等