Skip to content

Commit 2f42a85

Browse files
committed
convert negative numbers to positive before comparing
1 parent eb1d90f commit 2f42a85

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

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

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

1010
function isProperFraction(numerator, denominator) {
11-
// First check: both numerator and denominator should be positive
12-
if (numerator < 0 || denominator < 0) {
13-
return false;
14-
}
15-
11+
// First check: convert negative numbers to positive before comparing
12+
numerator = Math.abs(numerator);
13+
denominator = Math.abs(denominator);
1614
// Second check: numerator should be less than denominator
1715
if (numerator < denominator) {
1816
return true;

0 commit comments

Comments
 (0)