Skip to content

Commit

Permalink
replace multiple ifs with one switch
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 committed Dec 23, 2024
1 parent 46643b3 commit d919fca
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions frontend/cypress/support/helper/scoringSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,30 @@ function colorFromPercentage(percentage: number) {
}

function scoringValueFromPercentage(percentage: number): ScoringValue {
if (percentage >= 100) {
return {
failPercent: 0,
commitPercent: 0,
targetPercent: 0
};
} else if (percentage > 70) {
const targetPercent = (percentage - 70) * (100 / 30);
return {
failPercent: 100,
commitPercent: 100,
targetPercent: targetPercent
};
} else if (percentage > 30) {
const commitPercent = (percentage - 30) * (100 / 40);
return {
failPercent: 100,
commitPercent: commitPercent,
targetPercent: -1
};
switch (true) {
case percentage >= 100:
return {
failPercent: 0,
commitPercent: 0,
targetPercent: 0
};
case percentage > 70:
return {
failPercent: 100,
commitPercent: 100,
targetPercent: (percentage - 70) * (100 / 30)
};
case percentage > 30:
return {
failPercent: 100,
commitPercent: (percentage - 30) * (100 / 40),
targetPercent: -1
};
default:
return {
failPercent: percentage * (100 / 30),
commitPercent: -1,
targetPercent: -1
};
}
const failPercent = percentage * (100 / 30);
return {
failPercent: failPercent,
commitPercent: -1,
targetPercent: -1
};
}

0 comments on commit d919fca

Please sign in to comment.