Skip to content

Sheffield | May-2025 | Hassan Osman | Sprint-3 #580

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

HassanOHOsman
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

In this PR, I implemented the functions and tested them using Jest.

Questions

Ask any questions you have for your reviewer.

@HassanOHOsman HassanOHOsman added Needs Review Participant to add when requesting review 📅 Sprint 3 Assigned during Sprint 3 of this module labels Jun 20, 2025
@@ -1,7 +1,10 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

if (angle < 90) return "Acute angle";
Copy link
Contributor

Choose a reason for hiding this comment

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

angle <= 0 should also be considered as invalid angle.

Copy link
Author

Choose a reason for hiding this comment

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

updated.

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"


test("should identify angle over 360", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could generalise this test to "should identify angle not in the range (0, 360) as 'invalid'")

Comment on lines 2 to 6
if (numerator < denominator && (numerator/denominator) > 0) return true;
if (numerator > denominator) return false;
if (numerator < denominator && (numerator/denominator) < 0) return "Negative Fraction";
if (numerator === denominator ) return "Not really a fraction";

Copy link
Contributor

Choose a reason for hiding this comment

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

The function should return either true or false.

  • true means "the given numerator and denominator can form a proper fraction".
  • false means "the given numerator and denominator cannot form a proper fraction".

Note: If a function can possibly return different types of value, it would make consuming the return value difficult.


In mathematics, -4/7 == 4/-7, and -4/-7 == 4/7.
So, ideally isProperFraction() should recognise all of them as proper fractions.

Hint: If you compute the absolute value of both parameters inside the function first, the code can become much simpler.

Copy link
Author

Choose a reason for hiding this comment

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

That's totally ture CJ! I kept getting errors for some reason during tests, hence the multiple unnecessary scenarios I added. Anyway, function is now back to a simpler form.

Comment on lines 9 to 12
test("should return true for an improper fraction", () => {
expect(isProperFraction(11, 3)).toEqual(false);
expect(isProperFraction(7, 2)).toEqual(false);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The test description does not quite match the tests being performed.

Copy link
Author

Choose a reason for hiding this comment

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

silly me! lol 😅 Changed this now

Comment on lines 17 to 26
test("should return a negative fraction", () => {
expect(isProperFraction(-11, 3)).toEqual("Negative Fraction");
});


// Case 4: Identify Equal Numerator and Denominator:

test("should return a whole number", () => {
expect(isProperFraction(4, 4)).toEqual("Not really a fraction");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

After you have updated the function implementation, you may want to update these tests accordingly.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 2 to 5
if (card === "Ace of Spades") return 11;
if (card === "Number Cards") return "2-10";
if (card === "Ace") return "A";
if (card === "Face Cards") return "J, Q, K";
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably missed the spec of this function in Sprint-3/1-key-implement.

The expected parameter is a string in this format: "A♠", "2♠", "10♥", "K♥", "Q♦", "J♣". The rank value can be an invalid string but the last character is always a valid suit character.

getCardValue("A♠") should return 11.
getCardValue("K♠") should return 10.
getCardValue("2♠") should return 2.

Copy link
Author

Choose a reason for hiding this comment

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

Complete!

Comment on lines 2 to 6
if (str.includes(char) === true) {
return str.split(char).length -1;
} else {
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the value of str.split(char).length when str does not contain any character matching the value of char?
Can we utilise the finding from the previous question to simplify our code?

Copy link
Author

Choose a reason for hiding this comment

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

Simplified now.

Comment on lines 2 to 11
if (num === 1) {
return "1st";
} else if(num === 21) {
return "21st";
} else if(num === 2) {
return "2nd";
} else if(num === 22) {
return "22nd";
} else {
return `${num}th`;
Copy link
Contributor

Choose a reason for hiding this comment

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

getOrdinalNumber(101) should return "101st".
Consider looking up the rules to clarify how ordinal numbers are formed.

Copy link
Author

Choose a reason for hiding this comment

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

function has now been changed to accommodate all numbers.

if(count > 0) {
return str.repeat(count);
} else if (count === 0) {
return " ";
Copy link
Contributor

Choose a reason for hiding this comment

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

" " is a string containing one space. "" is an empty string (a string containing 0 characters).

Copy link
Author

Choose a reason for hiding this comment

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

corrected!

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jun 27, 2025
@HassanOHOsman HassanOHOsman added Needs Review Participant to add when requesting review and removed Reviewed Volunteer to add when completing a review labels Jun 29, 2025
@@ -1,6 +1,10 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
if (numerator >= denominator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A single comparison is enough if we can ensure the values being compared are positives.

That is, treat -2/3, 2/-3, and -2/-3 the same as 2/3. (They are all proper fractions).

Copy link
Author

Choose a reason for hiding this comment

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

added Math.abs() in the hope it would sort out the issue.

return 11;
break;
case "2♠":
return 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

A card can have one of four possible suits; the last character can also be a heart, club, or diamond. Your approach works great if you can extract the rank from the parameter first.

// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for K♠ card", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could generalise this test to "should return 10 for face cards (J, Q, K)" and check all three ranks J, Q, K). Same for "all number cards".

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jun 30, 2025
@HassanOHOsman HassanOHOsman added Needs Review Participant to add when requesting review and removed Reviewed Volunteer to add when completing a review labels Jun 30, 2025
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Changes look good.

Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js could still be improved.

Comment on lines 22 to 30
test("should return 10 for face cards (J, Q, K)", () => {
const faceCards = getCardValue("K♣︎");
expect(faceCards).toEqual(10);
});

test("should return 10 for Q♠ card", () => {
test("should return 10 for face cards (J, Q, K)", () => {
const faceCards = getCardValue("Q♠");
expect(faceCards).toEqual(10);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We could combine these tests as

test("should return 10 for face cards (J, Q, K)", () => {
    expect(getCardValue("J♣︎")).toEqual(10);
    expect(getCardValue("Q♠")).toEqual(10);
    expect(getCardValue("K♣︎")).toEqual(10);    
});

Copy link
Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@cjyuan cjyuan Jul 1, 2025

Choose a reason for hiding this comment

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

I don't think your implementation can pass some of the tests in this script. Have you tried executing this script to test your function implementation?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, some mistakes in the 2 expected values which have now been corrected.

Comment on lines 11 to 18
test("should append 'st' to numbers ending with 1 and not ending with 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});

test("should append 'st' to numbers ending with 1 and not ending with 11", () => {
expect(getOrdinalNumber(41)).toEqual("41st");
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Can be combined.

Copy link
Author

Choose a reason for hiding this comment

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

done!

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 1, 2025
@HassanOHOsman HassanOHOsman added Needs Review Participant to add when requesting review and removed Reviewed Volunteer to add when completing a review labels Jul 1, 2025
@HassanOHOsman
Copy link
Author

CJ, is there a way I could jests test a specific file, rather than running the whole test for all files? Tried doing so but keep ending up with errors :(

@cjyuan
Copy link
Contributor

cjyuan commented Jul 1, 2025

Changes are good! Good job.

You can run jest on a single file as
npx jest <filename> (you might need to run this command in the folder where the test script is located)

@cjyuan cjyuan added Complete Volunteer to add when work is complete and review comments have been addressed and removed Needs Review Participant to add when requesting review labels Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Volunteer to add when work is complete and review comments have been addressed 📅 Sprint 3 Assigned during Sprint 3 of this module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants