diff --git a/chapter-10/part.03-Replace_Nested_Conditional_With_Guard_Clauses/AdjustedCapital/after.js b/chapter-10/part.03-Replace_Nested_Conditional_With_Guard_Clauses/AdjustedCapital/after.js index d50e09a..08a720b 100644 --- a/chapter-10/part.03-Replace_Nested_Conditional_With_Guard_Clauses/AdjustedCapital/after.js +++ b/chapter-10/part.03-Replace_Nested_Conditional_With_Guard_Clauses/AdjustedCapital/after.js @@ -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; }