Skip to content

Commit e2c27cd

Browse files
committed
Implement isProperFraction with tests and fix variable
1 parent 0bd35d1 commit e2c27cd

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
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;
13-
}
13+
} else {
14+
return false;
15+
}
1416
}
1517

18+
1619
// The line below allows us to load the isProperFraction function into tests in other files.
1720
// This will be useful in the "rewrite tests with jest" step.
1821
module.exports = isProperFraction;
@@ -46,14 +49,26 @@ assertEquals(improperFraction, false);
4649
// target output: true
4750
// 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.
4851
const negativeFraction = isProperFraction(-4, 7);
52+
assertEquals(negativeFraction, true);
4953
// ====> complete with your assertion
5054

5155
// Equal Numerator and Denominator check:
5256
// Input: numerator = 3, denominator = 3
5357
// target output: false
5458
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5559
const equalFraction = isProperFraction(3, 3);
60+
assertEquals(equalFraction, false);
5661
// ====> complete with your assertion
5762

5863
// Stretch:
5964
// What other scenarios could you test for?
65+
const zeroNumerator = isProperFraction(0, 5);
66+
assertEquals(zeroNumerator, true);
67+
68+
const negativeDenominator = isProperFraction(4, -7);
69+
assertEquals(negativeDenominator, true);
70+
71+
const bothNegative = isProperFraction(-4, -7);
72+
assertEquals(bothNegative, true);
73+
74+

0 commit comments

Comments
 (0)