Skip to content

Commit eaeb7f7

Browse files
committed
Refactor card value validation to be more expressive
1 parent a17bab5 commit eaeb7f7

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ function getCardValue(card) {
1818
// Face cards
1919
if (["J", "Q", "K"].includes(rank)) return 10;
2020

21-
// Number cards
22-
const validNumbers = ["2","3","4","5","6","7","8","9","10"];
21+
// Number cards (2–10)
22+
const num = Number(rank);
2323

24-
if (validNumbers.includes(rank)) {
25-
return Number(rank);
24+
if (!isNaN(num) && num >= 2 && num <= 10) {
25+
return num;
2626
}
2727

2828
throw new Error("Invalid card");

0 commit comments

Comments
 (0)