From d919fcacdf986e3533647d7ab14207a22109524e Mon Sep 17 00:00:00 2001 From: Nevio Di Gennaro Date: Mon, 23 Dec 2024 14:03:43 +0100 Subject: [PATCH] replace multiple ifs with one switch --- .../cypress/support/helper/scoringSupport.ts | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/frontend/cypress/support/helper/scoringSupport.ts b/frontend/cypress/support/helper/scoringSupport.ts index dccd5600fe..c02502316b 100644 --- a/frontend/cypress/support/helper/scoringSupport.ts +++ b/frontend/cypress/support/helper/scoringSupport.ts @@ -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 - }; }