|
8 | 8 | // write one test at a time, and make it pass, build your solution up methodically |
9 | 9 |
|
10 | 10 | function isProperFraction(numerator, denominator) { |
11 | | - if (numerator < denominator) { |
| 11 | + // Proper fraction if absolute numerator is less than denominator |
| 12 | + if (Math.abs(numerator) < denominator) { |
12 | 13 | return true; |
| 14 | + } else { |
| 15 | + return false; |
13 | 16 | } |
14 | 17 | } |
15 | 18 |
|
@@ -46,14 +49,19 @@ assertEquals(improperFraction, false); |
46 | 49 | // target output: true |
47 | 50 | // 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. |
48 | 51 | const negativeFraction = isProperFraction(-4, 7); |
49 | | -// ====> complete with your assertion |
| 52 | +assertEquals(negativeFraction, true); |
50 | 53 |
|
51 | 54 | // Equal Numerator and Denominator check: |
52 | 55 | // Input: numerator = 3, denominator = 3 |
53 | 56 | // target output: false |
54 | 57 | // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. |
55 | 58 | const equalFraction = isProperFraction(3, 3); |
56 | | -// ====> complete with your assertion |
| 59 | +assertEquals(equalFraction, false); |
57 | 60 |
|
58 | 61 | // Stretch: |
59 | 62 | // What other scenarios could you test for? |
| 63 | +// Example: numerator = 0, denominator = 5 (0/5 is a proper fraction) |
| 64 | +const zeroNumerator = isProperFraction(0, 5); |
| 65 | +assertEquals(zeroNumerator, true); |
| 66 | + |
| 67 | +console.log("All tests ran! If no errors, all passed."); |
0 commit comments