-
-
Notifications
You must be signed in to change notification settings - Fork 218
London | 25-ITP-May | Houssam Lahlah | Sprint 3 | Coursework/sprint-3 #702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
2dd0a78
1bc5c74
b16d048
625c114
f5522e7
2f17199
5e31d7c
5cf1cfd
2d1e8dd
4723bb9
85a7125
a6dd884
cb53f9a
5a07227
a417fa0
461d0b6
057740b
48444ef
633a7af
6d8d7bb
50eaeb4
e2c7e37
276c348
28dfefd
c3ed0d1
f582fe6
6d4f165
9a891c6
cbb4e8d
4c99807
356d4c1
5040692
f20ecce
f1f5709
853d408
93ae4e9
6fcb856
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
function getCardValue(card) { | ||
const rank = card.slice(0, -1); // remove suit (last char) | ||
const rank = card.slice(0, -1); // remove suit | ||
|
||
if (!rank) throw new Error("Invalid card rank"); | ||
|
||
if (rank === "A") return 11; | ||
if (["K", "Q", "J"].includes(rank)) return 10; | ||
if (rank === "10") return 10; | ||
|
||
// Explicit check for number cards (2–9 only, no leading zeros or decimals) | ||
if (/^[2-9]$/.test(rank)) { | ||
return Number(rank); | ||
} | ||
if (/^(?:[2-9]|10)$/.test(rank)) return Number(rank); | ||
|
||
throw new Error("Invalid card rank"); | ||
|
||
} | ||
|
||
module.exports = getCardValue; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for question 5: a map/dict would also work, but might be a bit overly complicated for this task. My personal preference is if something can be done in 1-3 lines that's usually sufficient. If you had many more possible options, like if each of the 52 cards in the pack had a different rank, then you might consider a different structure. But this is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello LonMcGregor,
Thanks! I agree — for a small set of card ranks, the current approach is simple and readable. Using a map would work, but for this task it would be unnecessarily complicated. I see that for a larger set of unique ranks, a map would be a better choice.