Skip to content

Commit a62fa27

Browse files
Implement isProperFraction function to determine proper fractions and add corresponding tests
1 parent a4739dd commit a62fa27

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15-
}
1615

16+
if (denominator === 0) {
17+
return false; // A fraction with a denominator of 0 is undefined, so it's not a proper fraction.
18+
}
19+
if (numerator === 0) {
20+
return true; // A fraction with a numerator of 0 is a proper fraction (0/1 = 0).
21+
}
22+
if (Math.abs(numerator) < Math.abs(denominator)) {
23+
return true; // If the absolute value of the numerator is less than the absolute value of the denominator,
24+
// it's a proper fraction.
25+
}
26+
return false; // Otherwise, it's not a proper fraction.
27+
}
1728
// The line below allows us to load the isProperFraction function into tests in other files.
1829
// This will be useful in the "rewrite tests with jest" step.
1930
module.exports = isProperFraction;
@@ -31,3 +42,15 @@ function assertEquals(actualOutput, targetOutput) {
3142

3243
// Example: 1/2 is a proper fraction
3344
assertEquals(isProperFraction(1, 2), true);
45+
46+
// Example: 2/1 is not a proper fraction
47+
assertEquals(isProperFraction(2, 1), false);
48+
49+
// Example: 0/5 is a proper fraction
50+
assertEquals(isProperFraction(0, 5), true);
51+
52+
// Example: -5/10 is a proper fraction
53+
assertEquals(isProperFraction(-5, 10), true);
54+
55+
// Example: 0/0 is not a proper fraction
56+
assertEquals(isProperFraction(0, 0), false);

0 commit comments

Comments
 (0)