|
1 | | -const isProperFraction = require("./2-is-proper-fraction"); |
| 1 | +function isProperFraction(numerator, denominator) { |
| 2 | + // Case 1: Check for zero denominator (undefined) |
| 3 | + if (denominator === 0) return false; |
2 | 4 |
|
3 | | -test("should return true for a proper fraction", () => { |
4 | | - expect(isProperFraction(2, 3)).toEqual(true); |
5 | | -}); |
| 5 | + // Case 2: Check for negative values (numerator or denominator) |
| 6 | + if (numerator < 0 || denominator < 0) return false; |
6 | 7 |
|
7 | | -// Case 2: Identify Improper Fractions: |
| 8 | + // Case 3: Check for equal numerator and denominator |
| 9 | + if (numerator === denominator) return false; |
8 | 10 |
|
9 | | -// Case 3: Identify Negative Fractions: |
| 11 | + // Case 4: Check for proper fraction (numerator < denominator) |
| 12 | + return numerator < denominator; |
| 13 | +} |
| 14 | +module.exports = isProperFraction; |
| 15 | +// usage examples |
| 16 | +console.log(isProperFraction(2, 3)); // true |
| 17 | +console.log(isProperFraction(5, 3)); // false |
| 18 | +console.log(isProperFraction(3, 3)); // false |
| 19 | +console.log(isProperFraction(-2, 3)); // false |
| 20 | +console.log(isProperFraction(2, -3)); // false |
| 21 | +console.log(isProperFraction(0, 5)); // true (0 < 5) |
| 22 | +console.log(isProperFraction(2, 2)); // false |
10 | 23 |
|
11 | | -// Case 4: Identify Equal Numerator and Denominator: |
| 24 | +// Test cases for the isProperFraction function |
| 25 | +// test("should return true for a proper fraction", () => { |
| 26 | +// expect(isProperFraction(2, 3)).toEqual(true); |
| 27 | +// }); |
0 commit comments