Skip to content

Commit 498d7ae

Browse files
committed
I changed the code to only accept the exact strings for valid card ranks
1 parent 67710d6 commit 498d7ae

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
const chars = [...card];
12-
const rank = chars.slice(0, -1).join('');
13-
14-
if (rank === "A") {
15-
return 11;
16-
}
17-
const parsed = Number(rank);
18-
if (!Number.isNaN(parsed) && parsed >= 2 && parsed <= 9) {
19-
return parsed;
20-
}
21-
if (rank === "10" || rank === "J" || rank === "Q" || rank === "K"){
22-
return 10;
23-
}
11+
const rank = card.slice(0, -1);
12+
13+
if (rank === "A") return 11;
14+
if (["K", "Q", "J", "10"].includes(rank)) return 10;
15+
if (["2","3","4","5","6","7","8","9"].includes(rank)) return Number(rank);
16+
2417
throw new Error("invalid card rank.");
2518
}
2619

0 commit comments

Comments
 (0)