Skip to content

Commit 4b6f465

Browse files
authored
refactor: improve level calculator (#1946)
1 parent e522290 commit 4b6f465

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

src/calculateRank.js

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,13 @@ function calculateRank({
6363

6464
const normalizedScore = normalcdf(score, TOTAL_VALUES, ALL_OFFSETS) * 100;
6565

66-
let level = "";
67-
68-
if (normalizedScore < RANK_S_VALUE) {
69-
level = "S+";
70-
}
71-
if (
72-
normalizedScore >= RANK_S_VALUE &&
73-
normalizedScore < RANK_DOUBLE_A_VALUE
74-
) {
75-
level = "S";
76-
}
77-
if (
78-
normalizedScore >= RANK_DOUBLE_A_VALUE &&
79-
normalizedScore < RANK_A2_VALUE
80-
) {
81-
level = "A++";
82-
}
83-
if (normalizedScore >= RANK_A2_VALUE && normalizedScore < RANK_A3_VALUE) {
84-
level = "A+";
85-
}
86-
if (normalizedScore >= RANK_A3_VALUE && normalizedScore < RANK_B_VALUE) {
87-
level = "B+";
88-
}
66+
const level = (() => {
67+
if (normalizedScore < RANK_S_VALUE) return "S+";
68+
if (normalizedScore >= RANK_S_VALUE && normalizedScore < RANK_DOUBLE_A_VALUE) return "S";
69+
if (normalizedScore >= RANK_DOUBLE_A_VALUE && normalizedScore < RANK_A2_VALUE) return "A++";
70+
if (normalizedScore >= RANK_A2_VALUE && normalizedScore < RANK_A3_VALUE) return "A+"
71+
if (normalizedScore >= RANK_A3_VALUE && normalizedScore < RANK_B_VALUE) return "B+"
72+
})()
8973

9074
return { level, score: normalizedScore };
9175
}

0 commit comments

Comments
 (0)