Skip to content

Commit c6cbfe8

Browse files
committed
implementation for coercision abuse, whitepaces etc
1 parent 16959cf commit c6cbfe8

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
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 rank = card.slice(0, -1); //everything except the suit
12-
if (rank === "A") return 11;
11+
const rank = card.slice(0, -1);
1312

14-
if (["J", "Q", "K", "10"].includes(rank)) {
15-
return 10;
13+
// Numeric cards 2–10
14+
if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank)) {
15+
return Number(rank);
1616
}
1717

18-
const num = Number(rank);
19-
if (!isNaN(num) && num >= 2 && num <= 9) {
20-
return num;
21-
}
18+
// Face cards
19+
if (["J", "Q", "K"].includes(rank)) return 10;
20+
21+
// Ace
22+
if (rank === "A") return 11;
23+
2224
throw new Error("Invalid card rank");
23-
2425
}
2526

27+
2628
// The line below allows us to load the getCardValue function into tests in other files.
2729
// This will be useful in the "rewrite tests with jest" step.
2830
module.exports = getCardValue;

0 commit comments

Comments
 (0)