Skip to content

Commit e6d6e76

Browse files
committed
UPdate: fix isProperFraction function to handle negative numbers and add tests for zero numerator and denominator
1 parent ba7c348 commit e6d6e76

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Sprint-3/1-key-implement/2-is-proper-fraction.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) return true;
11+
// if (numerator < denominator) return true; it will not work for negative numbers
12+
return Math.abs(numerator) < Math.abs(denominator);
1213
}
1314

1415
// here's our helper again
@@ -41,13 +42,28 @@ assertEquals(improperFraction, false);
4142
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
4243
const negativeFraction = isProperFraction(-4, 7);
4344
// ====> complete with your assertion
45+
assertEquals(negativeFraction, true);
4446

4547
// Equal Numerator and Denominator check:
4648
// Input: numerator = 3, denominator = 3
4749
// target output: false
4850
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
4951
const equalFraction = isProperFraction(3, 3);
5052
// ====> complete with your assertion
51-
53+
assertEquals(equalFraction, false);
5254
// Stretch:
5355
// What other scenarios could you test for?
56+
57+
// Zero Numerator check:
58+
// Input: numerator = 0, denominator = 5
59+
// target output: true
60+
// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true.
61+
const zeroNumerator = isProperFraction(0, 5);
62+
assertEquals(zeroNumerator, true);
63+
64+
// Zero Denominator check:
65+
// Input: numerator = 4, denominator = 0
66+
// target output: false
67+
// Explanation: A fraction with a zero denominator is undefined. The function should return false to indicate it's not a valid proper fraction.
68+
const zeroDenominator = isProperFraction(4, 0);
69+
assertEquals(zeroDenominator, false);

0 commit comments

Comments
 (0)