Skip to content

Commit 3978458

Browse files
committed
fix: update isProperFraction to handle zero and negative cases
1 parent 0368e04 commit 3978458

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 8 additions & 1 deletion
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-
return numerator < denominator;
11+
if (denominator === 0) return false;
12+
return Math.abs(numerator) < Math.abs(denominator);
1213
}
1314

1415
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -59,3 +60,9 @@ assertEquals(equalFraction, false);
5960
// Explanation: Should return true when numerator is zero
6061
const zeroFraction = isProperFraction(0, 5);
6162
assertEquals(zeroFraction, true);
63+
64+
// New negative cases
65+
assertEquals(isProperFraction(-4, 3), false);
66+
assertEquals(isProperFraction(-2, 5), true);
67+
assertEquals(isProperFraction(-1, 1), false);
68+
assertEquals(isProperFraction(-2, -3), true);

0 commit comments

Comments
 (0)