Skip to content

Commit 9210c52

Browse files
committed
Implement isProperFraction function with tests
1 parent 4c78885 commit 9210c52

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

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

@@ -46,14 +48,24 @@ assertEquals(improperFraction, false);
4648
// target output: true
4749
// 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.
4850
const negativeFraction = isProperFraction(-4, 7);
51+
assertEquals(negativeFraction, true);
4952
// ====> complete with your assertion
5053

5154
// Equal Numerator and Denominator check:
5255
// Input: numerator = 3, denominator = 3
5356
// target output: false
5457
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5558
const equalFraction = isProperFraction(3, 3);
59+
assertEquals(equalFraction, false);
5660
// ====> complete with your assertion
5761

5862
// Stretch:
5963
// 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

Comments
 (0)