Skip to content

Commit 8a26524

Browse files
committed
Refactor getCardValue function to improve rank validation for number cards
1 parent f519980 commit 8a26524

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ function getCardValue(card) {
33
if (rank === "A") {
44
return 11;
55
}
6-
if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 10) {
7-
// checks for number cards 2-10
6+
if (/^(?:[2-9]|10)$/.test(rank)) {
87
return Number(rank);
9-
}
8+
} // Matches strings of only whole numbers 2-10
9+
// Handle 10 separately to avoid matching '1' alone
1010
if (["J", "Q", "K"].includes(rank)) {
1111
return 10;
1212
} else {

0 commit comments

Comments
 (0)