Skip to content
Open
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2dd0a78
explain Increment count variable by 1 after initialization.
HoussamLh Jun 17, 2025
1bc5c74
Create initials variable by extracting first characters of first, mid…
HoussamLh Jun 17, 2025
b16d048
create two variable and Extract directory and file extension parts fr…
HoussamLh Jun 17, 2025
625c114
Add comments explaining how num is calculated as a random integer bet…
HoussamLh Jun 17, 2025
f5522e7
Add explanation for incrementing count variable by 1 after initializa…
HoussamLh Jun 17, 2025
2f17199
Update 0.js
HoussamLh Jun 19, 2025
5e31d7c
Update 1.js
HoussamLh Jun 19, 2025
5cf1cfd
Update 2.js
HoussamLh Jun 19, 2025
2d1e8dd
Update 3.js
HoussamLh Jun 19, 2025
4723bb9
implement getAngleType function with all angle cases and tests
HoussamLh Jul 20, 2025
85a7125
implement isProperFraction with tests for positive, negative, equal n…
HoussamLh Jul 20, 2025
a6dd884
Implement getCardValue to return correct blackjack values for all val…
HoussamLh Jul 20, 2025
cb53f9a
Export complete getAngleType() function for Jest testing
HoussamLh Jul 20, 2025
5a07227
Add Jest tests for all angle types in getAngleType()
HoussamLh Jul 20, 2025
a417fa0
Implement isProperFraction to handle proper, improper, and negative f…
HoussamLh Jul 20, 2025
461d0b6
Add unit tests for isProperFraction covering all key scenarios
HoussamLh Jul 20, 2025
057740b
Implement getCardValue function with support for number, face, and ac…
HoussamLh Jul 20, 2025
48444ef
Add tests for getCardValue covering number cards, face cards, and inv…
HoussamLh Jul 20, 2025
633a7af
Revert Sprint-1 folder to CYF's original version
HoussamLh Jul 21, 2025
6d8d7bb
Implement countChar function to count occurrences of a character in a…
HoussamLh Jul 21, 2025
50eaeb4
Implement getOrdinalNumber to handle ordinal suffixes correctly
HoussamLh Jul 21, 2025
e2c7e37
Implement repeat function with parameters and error handling
HoussamLh Jul 21, 2025
276c348
Implement find function to locate character index in string with deta…
HoussamLh Jul 21, 2025
28dfefd
just to writing a missing bits.
HoussamLh Jul 21, 2025
c3ed0d1
Implement credit card validator function
HoussamLh Jul 21, 2025
f582fe6
fix: validate card ranks strictly and group tests by category
HoussamLh Sep 9, 2025
6d4f165
- this is just the json files
HoussamLh Sep 9, 2025
9a891c6
Merge branch 'coursework/sprint-3' of https://github.com/HoussamLh/Mo…
HoussamLh Sep 9, 2025
cbb4e8d
recover commits
HoussamLh Sep 9, 2025
4c99807
Test: add repeat.test.js to verify repeat function
HoussamLh Sep 9, 2025
356d4c1
Resolve the conflict marks from the file
HoussamLh Sep 10, 2025
5040692
Remove all the blank lines
HoussamLh Sep 10, 2025
f20ecce
Remove the looping over all number cards
HoussamLh Sep 10, 2025
f1f5709
simplify number card check with updated regex
HoussamLh Sep 10, 2025
853d408
expand Case 4 to cover more invalid card inputs
HoussamLh Sep 10, 2025
93ae4e9
Improve error message in getCardValue to include invalid card
HoussamLh Sep 10, 2025
6fcb856
Simplify digit sum check by returning boolean expression directly
HoussamLh Sep 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify number card check with updated regex
  • Loading branch information
HoussamLh committed Sep 10, 2025
commit f1f5709aa962f5ab11b731043513e420dfb1cf46
10 changes: 3 additions & 7 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
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;

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.

Copy link
Author

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.

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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for question 4: The goals of error messages are to inform the user of some code when a problem occurs. If you were using this code and you saw this error, would you understand what it meant? If so, the error is good enough.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello LonMcGregor,

Thanks for the feedback!

I see that error messages should be clear to the user. I could improve this one by including the invalid card value in the message, so it’s immediately obvious what caused the error and makes debugging easier.

}

module.exports = getCardValue;