Skip to content

Commit a3f7620

Browse files
committed
reorg-nested-code: break if statement chain and early return for isSeparated check
1 parent f496072 commit a3f7620

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/reorganizing-nested-code/index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
export function payAmount(employee) {
22
let result;
3-
if (employee.isSeparated) {
4-
result = { amount: 0, reasonCode: 'SEP' };
3+
if (employee.isSeparated) return { amount: 0, reasonCode: 'SEP' };
4+
if (employee.isRetired) {
5+
result = { amount: 0, reasonCode: 'RET' };
56
} else {
6-
if (employee.isRetired) {
7-
result = { amount: 0, reasonCode: 'RET' };
8-
} else {
9-
// potentially complicated logic to compute amount
10-
result = someFinalComputation();
11-
}
7+
// potentially complicated logic to compute amount
8+
result = someFinalComputation();
129
}
1310
return result;
1411
}

0 commit comments

Comments
 (0)