-
-
Notifications
You must be signed in to change notification settings - Fork 198
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 all commits
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
if (angle < 90) return "Acute angle"; | ||
if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
if (angle > 180 && angle < 360) return "Reflex angle"; | ||
throw new Error("Invalid angle"); | ||
} | ||
// Don't get bogged down in this detail | ||
// Jest uses CommonJS module syntax by default as it's quite old | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// we have just written the CommonJS module.exports syntax for you | ||
|
||
module.exports = getAngleType; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Explanation: | ||
// It checks if the absolute value of the numerator | ||
// is less than the absolute value of the denominator. | ||
|
||
|
||
function isProperFraction(numerator, denominator) { | ||
if (denominator === 0) { | ||
throw new Error("Denominator cannot be zero"); | ||
} | ||
|
||
return Math.abs(numerator) < Math.abs(denominator); | ||
} | ||
|
||
module.exports = isProperFraction; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function getCardValue(card) { | ||
const rank = card.slice(0, -1); // remove suit | ||
|
||
if (!rank) throw new Error(`Invalid card rank: ${card}`); | ||
|
||
if (rank === "A") return 11; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 (/^(?:[2-9]|10)$/.test(rank)) return Number(rank); | ||
|
||
throw new Error(`Invalid card rank: ${card}`); | ||
} | ||
|
||
module.exports = getCardValue; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
// Case 1: Ace | ||
test("should return 11 for Ace", () => { | ||
expect(getCardValue("A♠")).toEqual(11); | ||
expect(getCardValue("A♥")).toEqual(11); | ||
}); | ||
|
||
// Case 2: Number cards (sample of 2–10) | ||
test("should return the value of number cards (2, 5, 10)", () => { | ||
expect(getCardValue("2♣")).toEqual(2); | ||
expect(getCardValue("5♠")).toEqual(5); | ||
expect(getCardValue("10♥")).toEqual(10); | ||
}); | ||
|
||
// Case 3: Face cards (J, Q, K) | ||
test("should return 10 for face cards (J, Q, K)", () => { | ||
["J", "Q", "K"].forEach(rank => { | ||
expect(getCardValue(`${rank}♠`)).toEqual(10); | ||
expect(getCardValue(`${rank}♥`)).toEqual(10); | ||
}); | ||
}); | ||
|
||
// Case 4: Invalid cards | ||
test("should throw an error for invalid card rank", () => { | ||
const invalidCards = [ | ||
"Z♣", // invalid letter | ||
"0x02♠", // invalid rank | ||
"2.1♠", // decimal | ||
"0002♠", // leading zeros | ||
"", // empty string | ||
"♠" // suit only | ||
]; | ||
|
||
invalidCards.forEach(card => { | ||
expect(() => getCardValue(card)).toThrow("Invalid card rank"); | ||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
<<<<<<< HEAD:Sprint-3/3-mandatory-practice/implement/count.js | ||
let count = 0; | ||
for (let char of stringOfCharacters) { | ||
if (char === findCharacter) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
======= | ||
return 5 | ||
>>>>>>> 8f3d6cf2d1733da02a010f1a16c46b8b5ab4c491:Sprint-3/2-practice-tdd/count.js | ||
} | ||
|
||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function getOrdinalNumber(num) { | ||
const suffixes = ["th", "st", "nd", "rd"]; | ||
const value = num % 100; | ||
if (value >= 11 && value <= 13) { | ||
return num + "th"; | ||
} | ||
const lastDigit = num % 10; | ||
const suffix = suffixes[lastDigit] || "th"; | ||
return num + suffix; | ||
} | ||
|
||
module.exports = getOrdinalNumber; |
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.
Does this correctly handle all cases? What about negative improper fractions?
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,
Thank you for the comment!
After checking, the function already handles negative improper fractions correctly because it compares the absolute values of the numerator and denominator. This way, whether the numerator or denominator is negative, the function still correctly determines if the fraction is proper.
I also included a check for denominator === 0 to avoid division by zero.