Skip to content

Commit bd89fda

Browse files
committed
Now using Math.abs
1 parent 22ad256 commit bd89fda

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
return numerator >= 0 && denominator > 0 && numerator < denominator;
14+
if (denominator === 0) {
15+
return false;
16+
}
17+
return Math.abs(numerator) < Math.abs(denominator);
1518
}
1619

1720
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -35,5 +38,9 @@ assertEquals(isProperFraction(3, 5), true);
3538
assertEquals(isProperFraction(0, 5), true);
3639
assertEquals(isProperFraction(4, 4), false);
3740
assertEquals(isProperFraction(7, 3), false);
38-
assertEquals(isProperFraction(-1, 2), false);
39-
assertEquals(isProperFraction(4, 0), false);
41+
assertEquals(isProperFraction(-1, 2), true);
42+
assertEquals(isProperFraction(4, 0), false);
43+
assertEquals(isProperFraction(-4, 5), true);
44+
assertEquals(isProperFraction(4, -5), true);
45+
assertEquals(isProperFraction(-4, -5), true);
46+
assertEquals(isProperFraction(-9, 5), false);

0 commit comments

Comments
 (0)