Skip to content

Commit c2f900d

Browse files
committed
implement 2 is proper fraction
1 parent 2c8b209 commit c2f900d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
11+
if (Math.abs(numerator) < Math.abs(denominator)) {
1212
return true;
1313
}
14+
return false;
1415
}
1516

1617
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -47,13 +48,34 @@ assertEquals(improperFraction, false);
4748
// 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.
4849
const negativeFraction = isProperFraction(-4, 7);
4950
// ====> complete with your assertion
51+
assertEquals(negativeFraction, true);
5052

5153
// Equal Numerator and Denominator check:
5254
// Input: numerator = 3, denominator = 3
5355
// target output: false
5456
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5557
const equalFraction = isProperFraction(3, 3);
5658
// ====> complete with your assertion
59+
assertEquals(equalFraction, false);
5760

5861
// Stretch:
59-
// What other scenarios could you test for?
62+
// What other scenarios could you test for? Zero numerator => always proper
63+
const zeroNumerator = isProperFraction(0, 10);
64+
assertEquals(zeroNumerator, true);
65+
66+
//Negarive denominator => use absoluet values
67+
const negativeDenominator = isProperFraction(3, -5);
68+
assertEquals(negativeDenominator, true);
69+
70+
//Both negatives
71+
const bothNegative = isProperFraction(-2, -3);
72+
assertEquals(bothNegative, true);
73+
74+
//fractions like 8/8 should be false
75+
const improperEqual = isProperFraction(9, 9);
76+
assertEquals(improperEqual, false);
77+
78+
//zero denominator - maths says undefined so can return false or throw error
79+
const zeroDenominator = isProperFraction(1, 0);
80+
assertEquals(zeroDenominator, false);
81+

0 commit comments

Comments
 (0)