Skip to content

Commit 9d3f83b

Browse files
committed
feat: implement isProperFraction function with tests for main cases
1 parent bf6c25f commit 9d3f83b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

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

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
12-
return true;
13-
}
11+
// A proper fraction is defined as a fraction a/b where:
12+
// 1. The numerator (a) is a positive integer
13+
// 2. The denominator (b) is a positive integer
14+
// 3. The absolute value of the numerator is less than the absolute value of the denominator:
15+
// |a| < |b|
16+
return Math.abs(numerator) < Math.abs(denominator);
1417
}
1518

1619
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -46,14 +49,22 @@ assertEquals(improperFraction, false);
4649
// target output: true
4750
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
4851
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
52+
assertEquals(negativeFraction, true);
5053

5154
// Equal Numerator and Denominator check:
5255
// Input: numerator = 3, denominator = 3
5356
// target output: false
5457
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5558
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
59+
assertEquals(equalFraction, false);
5760

5861
// Stretch:
5962
// What other scenarios could you test for?
63+
64+
// Given the definition of a proper fraction, cases involving values such as zero or floating-point numbers should be considered false as they are not positive integers (natural numbers):
65+
// - Where either the numerator or denominator is zero, the function should return false.
66+
// - Floating-point numbers in the function should return false, as proper fractions are defined for integers only.
67+
68+
// The method `Number.isInteger()` can be used to check for positive integers by:
69+
// - Using `Math.abs()` to handle negative values when comparing numerator and denominator.
70+
// - Then checking if both numerator and denominator are positive integers using `Number.isInteger()` and greater than zero.

0 commit comments

Comments
 (0)