Skip to content

Commit bf0e4d8

Browse files
committed
validate negative numbers in the function
1 parent 3ba56dc commit bf0e4d8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Sprint-3/implement/is-proper-fraction.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ function isProperFraction(numerator, denominator) {
4646
}
4747

4848
// Proper fraction if the absolute value of the numerator is less than the denominator
49-
return Math.abs(numerator) < denominator;
49+
return Math.abs(numerator) < Math.abs(denominator);
5050
}
5151

52+
// Test cases
53+
console.log(isProperFraction(3, 6)); // true
54+
console.log(isProperFraction(-3, 6)); // true
55+
console.log(isProperFraction(5, 5)); // false
56+
console.log(isProperFraction(-4, 7)); // true
57+
console.log(isProperFraction(4, -7)); // true
58+
console.log(isProperFraction(-4, -7)); // true
59+
console.log(isProperFraction(9, 0)); // Error: Denominator cannot be zero
5260

53-
console.log(isProperFraction(3, 6));
54-
console.log(isProperFraction(-3, 6));
55-
console.log(isProperFraction(9, 0));
56-
console.log(isProperFraction(5, 5));

0 commit comments

Comments
 (0)