We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f20ecce commit f1f5709Copy full SHA for f1f5709
Sprint-3/2-mandatory-rewrite/3-get-card-value.js
@@ -1,18 +1,14 @@
1
function getCardValue(card) {
2
- const rank = card.slice(0, -1); // remove suit (last char)
+ const rank = card.slice(0, -1); // remove suit
3
4
if (!rank) throw new Error("Invalid card rank");
5
6
if (rank === "A") return 11;
7
if (["K", "Q", "J"].includes(rank)) return 10;
8
- if (rank === "10") return 10;
9
-
10
- // Explicit check for number cards (2–9 only, no leading zeros or decimals)
11
- if (/^[2-9]$/.test(rank)) {
12
- return Number(rank);
13
- }
+ if (/^(?:[2-9]|10)$/.test(rank)) return Number(rank);
14
15
throw new Error("Invalid card rank");
16
}
17
18
module.exports = getCardValue;
+
0 commit comments