|
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 | + if (Math.abs(numerator) < Math.abs(denominator)) { |
12 | 12 | return true; |
| 13 | + } else { |
| 14 | + return false; |
13 | 15 | } |
14 | 16 | } |
15 | 17 |
|
@@ -46,14 +48,24 @@ assertEquals(improperFraction, false); |
46 | 48 | // target output: true |
47 | 49 | // 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 | 50 | const negativeFraction = isProperFraction(-4, 7); |
| 51 | +assertEquals(negativeFraction, true); |
49 | 52 | // ====> complete with your assertion |
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); |
| 59 | +assertEquals(equalFraction, false); |
56 | 60 | // ====> complete with your assertion |
57 | 61 |
|
58 | 62 | // Stretch: |
59 | 63 | // What other scenarios could you test for? |
| 64 | +const zeroNumerator = isProperFraction(0, 5); |
| 65 | +assertEquals(zeroNumerator, true); |
| 66 | + |
| 67 | +const negativeDenominator = isProperFraction(4, -7); |
| 68 | +assertEquals(negativeDenominator, true); |
| 69 | + |
| 70 | +const bothNegative = isProperFraction(-4, -7); |
| 71 | +assertEquals(bothNegative, true); |
0 commit comments