Skip to content

Commit 06c3aa1

Browse files
committed
Fix: strict validation for card values (prevent invalid numeric formats)
1 parent c0f5e98 commit 06c3aa1

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ function getCardValue(card) {
3838
}
3939

4040
if (rank === "A") return 11;
41-
if (rank === "J" || rank === "Q" || rank === "K") return 10;
41+
if (["J", "Q", "K"].includes(rank)) return 10;
4242

43-
const numberValue = Number(rank);
44-
45-
if (numberValue >= 2 && numberValue <= 10) {
46-
return numberValue;
43+
const validNumbers = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];
44+
45+
if (!validNumbers.includes(rank)) {
46+
return Number(rank);
4747
}
4848

49+
4950
throw new Error("Invalid card");
5051
}
5152

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"keywords": [],
1010
"author": "Code Your Future",
1111
"license": "ISC",
12-
"dependencies": {
13-
"jest": "^29.7.0"
12+
"devDependencies": {
13+
"jest": "^30.2.0"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)