-
-
Notifications
You must be signed in to change notification settings - Fork 261
Glasgow | 25-ITP-SEP | Shreef Ibrahim | Sprint 3 | Coursework #717
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 10 commits
4455f27
0967a9e
23cb65d
5e53e5d
0e4389e
9bc3e9d
0d3fde4
f438971
ef697bb
deb0fe6
ed29b44
3919856
1b12778
e638e78
fcaf871
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,22 @@ test("should return 11 for Ace of Spades", () => { | |
| }); | ||
|
|
||
| // Case 2: Handle Number Cards (2-10): | ||
| test("Should return numeric value(8) for Number Cards (2-10)", () => { | ||
| const aceofSpades = getCardValue("8♠"); | ||
| expect(aceofSpades).toEqual(8); | ||
| }); | ||
| // Case 3: Handle Face Cards (J, Q, K): | ||
| test("should return the value 10, a card with a rank of ('10', 'J', 'Q', or 'K')", () => { | ||
| const aceofSpades = getCardValue("K"); | ||
|
||
| expect(aceofSpades).toEqual(10); | ||
| }); | ||
| // Case 4: Handle Ace (A): | ||
| test("should return the value 11,for a card with a rank of 'A' ", () => { | ||
| const aceofSpades = getCardValue("A"); | ||
| expect(aceofSpades).toEqual(11); | ||
| }); | ||
| // Case 5: Handle Invalid Cards: | ||
| test("should throw an error,with an invalid rank 'OL'", () => { | ||
| const aceofSpades = getCardValue("OL"); | ||
| expect(aceofSpades).toBe("Invalid card rank"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| function countChar(stringOfCharacters, findChar) { | ||
| let count = 0; | ||
| for (const char of stringOfCharacters) { | ||
| if (char === findChar) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| let last2Digit = num % 100; | ||
| let las1Digit = num % 10; | ||
| if (last2Digit >= 11 && last2Digit <= 13) { | ||
| return num + "th"; | ||
| } | ||
| if (las1Digit === 1) { | ||
|
||
| return num + "st"; | ||
| } else if (las1Digit === 2) { | ||
| return num + "nd"; | ||
| } else if (las1Digit === 3) { | ||
| return num + "rd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| if (count < 0) { | ||
| return "Count must be non-negative"; | ||
| } | ||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeat; |
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.
What circumstances would you have a card of length 1? A card in this case is always a rank + a symbol
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.
Thanks for pointing that. I checked that if the card is a single character (length 1) for example, "A" it returns 10 which is not true , because this line ( let rank = card.length === 1 ? card: card.slice(0, -1); ) is handling the case where the card is only one character long, Instead of the card should always include both the rank and the suit.
i have updated the function.