Skip to content

Commit

Permalink
refactor: 두 if문은 같은 결과를 내는 조건을 포함하므로 조건식을 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
imseongtae committed Oct 19, 2020
1 parent 64447cb commit 8971361
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// 보호구문으로 바꾸는 리팩터링을 수행할 때 조건을 역으로 만드는 경우
function adjustedCapital(anInstrument) {
let result = 0;
// 보호 구문을 추가하면서 조건을 역으로 바꿈
if (anInstrument.capital <= 0) return result;
// not 연산자를 통해 분리한 구문을 간소화(조건을 역으로)
if (anInstrument.interestRate <= 0 || anInstrument.duration <= 0) return result;
// 두 if문은 같은 결과를 내는 조건을 포함하므로 조건식을 통합
if (
anInstrument.capital <= 0 ||
anInstrument.interestRate <= 0 ||
anInstrument.duration <= 0
) {
return result;
}
result = (anInstrument.income / anInstrument.duration) * anInstrument.adjustmentFactor;
return result;
}
Expand Down

0 comments on commit 8971361

Please sign in to comment.