|
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 | | - } |
| 13 | + } else return false; |
14 | 14 | } |
15 | 15 |
|
16 | 16 | // The line below allows us to load the isProperFraction function into tests in other files. |
@@ -46,14 +46,19 @@ assertEquals(improperFraction, false); |
46 | 46 | // target output: true |
47 | 47 | // 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 | 48 | const negativeFraction = isProperFraction(-4, 7); |
49 | | -// ====> complete with your assertion |
| 49 | +assertEquals(negativeFraction, true); |
50 | 50 |
|
51 | 51 | // Equal Numerator and Denominator check: |
52 | 52 | // Input: numerator = 3, denominator = 3 |
53 | 53 | // target output: false |
54 | 54 | // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. |
55 | 55 | const equalFraction = isProperFraction(3, 3); |
56 | | -// ====> complete with your assertion |
| 56 | +assertEquals(equalFraction, false); |
57 | 57 |
|
58 | 58 | // Stretch: |
59 | 59 | // What other scenarios could you test for? |
| 60 | +const doublenegativeFraction = isProperFraction(-3, -5); |
| 61 | +assertEquals(doublenegativeFraction, true); |
| 62 | + |
| 63 | +const zeronumeratorFraction = isProperFraction(0, 4); |
| 64 | +assertEquals(zeronumeratorFraction, true); |
0 commit comments