|
11 | 11 | // execute the code to ensure all tests pass. |
12 | 12 |
|
13 | 13 | function isProperFraction(numerator, denominator) { |
14 | | - // TODO: Implement this function |
15 | | - if (denominator <= 0) { |
16 | | - return false; // not a valid fraction |
| 14 | + // Denominator cannot be zero |
| 15 | + if (denominator === 0) { |
| 16 | + return false; |
17 | 17 | } |
18 | | - if (numerator < denominator && numerator >= 0) { |
19 | | - return true; |
20 | | - } |
21 | | - return false; |
| 18 | + // A proper fraction satisfies: numerator < denominator |
| 19 | + // This correctly handles all sign combinations |
| 20 | + return Math.abs(numerator) < Math.abs(denominator); |
22 | 21 | } |
23 | 22 |
|
24 | 23 | // The line below allows us to load the isProperFraction function into tests in other files. |
@@ -63,15 +62,15 @@ assertEquals(numeratorLarger, false); |
63 | 62 | const zeroDenominator = isProperFraction(5, 0); |
64 | 63 | assertEquals(zeroDenominator, false); |
65 | 64 |
|
66 | | -// Example: 2/-6 is an invalid fraction |
67 | | -// Negative denominator makes fraction invalid |
| 65 | +// Example: 2/-6 is a proper fraction |
| 66 | +// Negative denominator is now allowed |
68 | 67 | const negativeDenominator = isProperFraction(2, -6); |
69 | | -assertEquals(negativeDenominator, false); |
| 68 | +assertEquals(negativeDenominator, true); |
70 | 69 |
|
71 | 70 | // Example: -1/4 is an invalid fraction |
72 | | -// Negative numerator makes fraction negative |
| 71 | +// Negative numerator is now allowed |
73 | 72 | const negativeNumerator = isProperFraction(-1, 4); |
74 | | -assertEquals(negativeNumerator, false); |
| 73 | +assertEquals(negativeNumerator, true); |
75 | 74 |
|
76 | 75 | // Example: 1/100 is a positive fraction |
77 | 76 | // Small numerator with large denominator |
|
0 commit comments