✏️1.4 statement() 함수 쪼개기
statement()함수의 테스트는 어떻게 구성하면 될까?
statement()함수의 테스트는 어떻게 구성하면 될까?statement()함수 쪼개기
statement()함수 쪼개기function amountFor(perf, play) { // 값이 바뀌지 않는 변수는 매개변수로 전달
let thisAmount = 0; // 변수를 초기화하는 코드
switch (play.type) {
case "tragedy":
thisAmount = 40000;
if (perf.audience > 30) {
thisAmount += 1000 * (perf.audience - 30);
}
break;
case "comedy":
thisAmount = 30000;
if (perf.audience > 20) {
thisAmount += 1000 + 500 * (perf.audience - 20);
}
thisAmount += 300 * perf.audience
break;
default:
throw new Error(`알 수 없는 장르: ${play.type}`);
}
return thisAmound; // 함수 안에서 값이 바뀌는 변수 변환함수 추출 후 변수 이름 더 명확하게 바꾸기
적립 포인트 계산 코드 추출하기
format 변수 제거하기
함수 선언 바꾸기
volumeCredits 변수 제거하기
문장 슬라이드하기 volumeCredits 변수를 선언하는 문장을 반복문 바로 앞으로 옮긴다
Last updated