|
1 | 1 | // Implement a function isProperFraction |
2 | 2 | // Write assertions for your function to check it works in different cases |
3 | | -// Terms: |
| 3 | +// Terms:A proper fraction is when: |
| 4 | +//the absolute value of the numerator is less than the denominator |
| 5 | + |
4 | 6 | // Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j |
5 | 7 | // Written here like this: 1/2 == Numerator/Denominator |
6 | 8 | // the first test and first case is written for you |
7 | | -// complete the rest of the tests and cases |
8 | | -// write one test at a time, and make it pass, build your solution up methodically |
| 9 | +// 1-complete the rest of the tests and cases |
9 | 10 |
|
| 11 | +// 2-write one test at a time, and make it pass, build your solution up methodically |
| 12 | +//1- |
10 | 13 | function isProperFraction(numerator, denominator) { |
11 | | - if (numerator < denominator) { |
| 14 | + if (Math.abs(numerator) < Math.abs(denominator)) { |
12 | 15 | return true; |
| 16 | + } else { |
| 17 | + return false; |
13 | 18 | } |
14 | 19 | } |
15 | 20 |
|
@@ -46,14 +51,20 @@ assertEquals(improperFraction, false); |
46 | 51 | // target output: true |
47 | 52 | // 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 | 53 | const negativeFraction = isProperFraction(-4, 7); |
49 | | -// ====> complete with your assertion |
| 54 | +assertEquals(negativeFraction, true); |
| 55 | + |
50 | 56 |
|
51 | 57 | // Equal Numerator and Denominator check: |
52 | 58 | // Input: numerator = 3, denominator = 3 |
53 | 59 | // target output: false |
54 | 60 | // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. |
55 | 61 | const equalFraction = isProperFraction(3, 3); |
56 | | -// ====> complete with your assertion |
| 62 | +assertEquals(equalFraction, false); |
| 63 | + |
| 64 | + |
57 | 65 |
|
58 | 66 | // Stretch: |
59 | 67 | // What other scenarios could you test for? |
| 68 | +const negativeDenominator = isProperFraction(3, -5); |
| 69 | +assertEquals(negativeDenominator, true); |
| 70 | +const bothNegative = isProperFraction(-2, -6); |
0 commit comments