Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

function isProperFraction(numerator, denominator) {
if (denominator === 0) return false;
if (numerator < 1) numerator = numerator * -1;
if (numerator < 1) numerator = Math.abs(numerator) ;
if (denominator < 1) denominator = Math.abs(denominator);
Copy link
Contributor

Choose a reason for hiding this comment

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

denominator < 0 is probably more expressive in the sense that it is closer to the definition of "negative number".


if (numerator < denominator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ function getCardValue(card) {
if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
}
const convertTheStringtoNumber = Number(rank);
if (convertTheStringtoNumber >= 2 && convertTheStringtoNumber <= 10) {
return convertTheStringtoNumber;
} else {
return "Invalid card rank";
}

const validRank = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];
if (validRank.includes(rank)) {
return Number(rank);
} else return "Invalid card rank";
}
// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ test("returns true for a negative proper fraction( absolute value of the numerat
test("returns false when numerator equals denominator", () => {
expect(isProperFraction(9, 9)).toEqual(false);
});

test("return false when numerator equals denominator when both are negative", () => {
expect(isProperFraction(-4, -4)).toEqual(false);
});

test("returns false for a negative proper fraction( absolute value of the denominator is less than the numerator)", () => {
expect(isProperFraction(-7, 4)).toEqual(false);
});
Comment on lines +26 to +28
Copy link
Contributor

Choose a reason for hiding this comment

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

  • -7/4 is considered a negative improper fraction.

test("returns false when denominator is zero", () => {
expect(isProperFraction(3, 0)).toEqual(false);
});