Skip to content

Commit 50ee9ef

Browse files
committed
corrected test for numerator is 0 to a proper fraction, and removed unnecessary if statements
1 parent 035e27e commit 50ee9ef

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

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

1010
function isProperFraction(numerator, denominator) {
11-
if (Math.abs(numerator) < Math.abs(denominator)) {
11+
const absNumerator = Math.abs(numerator);
12+
const absDenominator = Math.abs(denominator);
13+
14+
if (absDenominator === 0) {
15+
return `you cannot have zero as a denominator`;
16+
}
17+
18+
if (absNumerator < absDenominator) {
1219
return true;
13-
} else if (numerator > denominator) {
14-
return false;
15-
} else if (numerator === denominator) {
16-
return false;
17-
} else if (numerator === 0) {
18-
return false;
1920
}
21+
22+
return false;
2023
}
2124

2225
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -67,4 +70,8 @@ assertEquals(equalFraction, false);
6770
// What other scenarios could you test for?
6871
//we can test if the numerator is 0
6972
const zeroFraction = isProperFraction(0, 4);
70-
assertEquals(zeroFraction, false);
73+
assertEquals(zeroFraction, true);
74+
75+
//we can test if the denominator is 0
76+
const indefiniteFraction = isProperFraction(3, 0);
77+
assertEquals(indefiniteFraction, `you cannot have zero as a denominator`);

0 commit comments

Comments
 (0)