Skip to content

Commit d58910a

Browse files
committed
used regex pattern to check for ranks and removed includes method
1 parent 5fa3d08 commit d58910a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@ function getCardValue(card) {
1515
return false;
1616
}
1717

18+
const pattern = /^(?:[2-9]|10)$/;
1819
let rank = card.slice(0, card.length - 1);
1920

2021
if (strictNumber(rank)) {
21-
if (
22-
Number.isInteger(Number(rank)) &&
23-
Number(rank) > 1 &&
24-
Number(rank) <= 10
25-
) {
22+
if (pattern.test(Number(rank))) {
2623
return Number(rank);
2724
}
2825
}
2926

30-
if (rank.includes("J") || rank.includes("Q") || rank.includes("K")) {
27+
const faceCardPattern = /^[JQK]$/;
28+
29+
if (faceCardPattern.test(rank)) {
3130
return 10;
32-
} else if (rank.includes("A")) {
31+
} else if (/^A$/.test(rank)) {
3332
return 11;
3433
} else {
3534
return "Invalid card rank.";
3635
}
3736
}
38-
37+
console.log(`Jack will give ${getCardValue("J♥")}`);
3938
// The line below allows us to load the getCardValue function into tests in other files.
4039
// This will be useful in the "rewrite tests with jest" step.
4140
module.exports = getCardValue;

0 commit comments

Comments
 (0)