-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 변수 제거를 통해 변수 하나가 두 가지 용도로 쓰이는 경우 방지
- Loading branch information
1 parent
8971361
commit c5cde31
Showing
1 changed file
with
4 additions
and
4 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
chapter-10/part.03-Replace_Nested_Conditional_With_Guard_Clauses/AdjustedCapital/after.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
// 보호구문으로 바꾸는 리팩터링을 수행할 때 조건을 역으로 만드는 경우 | ||
function adjustedCapital(anInstrument) { | ||
let result = 0; | ||
// let result = 0; // 변수 제거를 통해 변수 하나가 두 가지 용도로 쓰이는 경우 방지 | ||
// 두 if문은 같은 결과를 내는 조건을 포함하므로 조건식을 통합 | ||
if ( | ||
anInstrument.capital <= 0 || | ||
anInstrument.interestRate <= 0 || | ||
anInstrument.duration <= 0 | ||
) { | ||
return result; | ||
return 0; // 보호 구문이 발동할 때 반환 | ||
} | ||
result = (anInstrument.income / anInstrument.duration) * anInstrument.adjustmentFactor; | ||
return result; | ||
// 계산의 최종 결과를 반환 | ||
return (anInstrument.income / anInstrument.duration) * anInstrument.adjustmentFactor; | ||
} | ||
|
||
module.exports = adjustedCapital; |