Skip to content

Commit 47809af

Browse files
committed
Change expected output to true for proper fractions with negative numerators or denominators
1 parent 46aee35 commit 47809af

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,35 @@
77
// complete the rest of the tests and cases
88
// write one test at a time, and make it pass, build your solution up methodically
99

10-
11-
1210
function isProperFraction(numerator, denominator) {
13-
let actualOutput;
14-
// Denominator must be positive
15-
if (denominator <= 0) {
16-
actualOutput = false;
11+
//if numerator or denominator is not an integer, it is not a proper
12+
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
13+
return false;
14+
}
15+
// if absolute numerator is strictly equal to zero or absolute denominator, it is not a proper fraction
16+
if (Math.abs(numerator) === 0 || Math.abs(denominator) === 0) {
17+
return false;
1718
}
18-
// Numerator must be positive and smaller than denominator
19-
else if (numerator > 0 && numerator < denominator) {
20-
actualOutput = true;
19+
// if absolute numerator is strictly equals to absolute, it is not a proper fraction
20+
else if (Math.abs(numerator) === Math.abs(denominator)) {
21+
return false;
2122
}
23+
24+
// if absolute Numerator is greater than zero and smaller than absolute denominator, it is a proper fraction
25+
else if (Math.abs(numerator) < Math.abs(denominator)) {
26+
return true;
27+
}
28+
2229
// All other cases are not proper fractions
2330
else {
24-
actualOutput = false;
31+
return false;
2532
}
26-
return actualOutput;
33+
2734
}
2835

36+
2937
// The line below allows us to load the isProperFraction function into tests in other files.
30-
// This will be useful in the "rewrite tests with jest" step.
38+
// This will be useful in the "rewrite tests with jest" step
3139
module.exports = isProperFraction;
3240

3341
// here's our helper again
@@ -60,7 +68,7 @@ assertEquals(improperFraction, false);
6068
// Explanation: Negative numerator should not count as proper fraction.
6169
const negativeFraction = isProperFraction(-4, 7);
6270
// ====> complete with your assertion
63-
assertEquals(negativeFraction, false);
71+
assertEquals(negativeFraction, true);
6472

6573
// Equal Numerator and Denominator check:
6674
// Input: numerator = 3, denominator = 3
@@ -85,14 +93,14 @@ assertEquals(zeroNumerator, false);
8593
// Target output: false
8694
// Explanation: Denominator must be positive for a proper fraction.
8795
const negativeDenominator = isProperFraction(3, -5);
88-
assertEquals(negativeDenominator, false);
96+
assertEquals(negativeDenominator, true);
8997

9098
// Both Negative check:
9199
// Input: numerator = -2, denominator = -3
92100
// Target output: false
93101
// Explanation: Proper fractions must have positive numerator and denominator.
94102
const bothNegative = isProperFraction(-2, -3);
95-
assertEquals(bothNegative, false);
103+
assertEquals(bothNegative, true);
96104

97105
// Zero Denominator check:
98106
// Input: numerator = 1, denominator = 0

0 commit comments

Comments
 (0)