Skip to content

Commit ac02de3

Browse files
committed
Completed 2-is-proper-fraction.js exercise
1 parent 1f89522 commit ac02de3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (denominator <= 0) {
16+
return false; // not a valid fraction
17+
}
18+
if (numerator < denominator && numerator >= 0) {
19+
return true;
20+
}
21+
return false;
1522
}
1623

1724
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +38,42 @@ function assertEquals(actualOutput, targetOutput) {
3138

3239
// Example: 1/2 is a proper fraction
3340
assertEquals(isProperFraction(1, 2), true);
41+
42+
// Example: 3/5 is a postive proper fraction
43+
const properFraction = isProperFraction(3, 5);
44+
assertEquals(properFraction, true);
45+
46+
// Example: 0/4 is a proper fraction with zero numerator
47+
// Zero numerator is allowed in proper fractions
48+
const zeroNumerator = isProperFraction(0, 4);
49+
assertEquals(zeroNumerator, true);
50+
51+
// Example: 7/7 is an improper fraction,
52+
// numerator equals denominator
53+
const equalFraction = isProperFraction(7, 7);
54+
assertEquals(equalFraction, false);
55+
56+
// Example: 8/3 is an improper fraction,
57+
// numerator is larger
58+
const numeratorLarger = isProperFraction(8, 3);
59+
assertEquals(numeratorLarger, false);
60+
61+
// Example: 5/0 is an invalid fraction
62+
// Division by zero is not a valid fraction
63+
const zeroDenominator = isProperFraction(5, 0);
64+
assertEquals(zeroDenominator, false);
65+
66+
// Example: 2/-6 is an invalid fraction
67+
// Negative denominator makes fraction invalid
68+
const negativeDenominator = isProperFraction(2, -6);
69+
assertEquals(negativeDenominator, false);
70+
71+
// Example: -1/4 is an invalid fraction
72+
// Negative numerator makes fraction negative
73+
const negativeNumerator = isProperFraction(-1, 4);
74+
assertEquals(negativeNumerator, false);
75+
76+
// Example: 1/100 is a positive fraction
77+
// Small numerator with large denominator
78+
const smallFraction = isProperFraction(1, 100);
79+
assertEquals(smallFraction, true);

0 commit comments

Comments
 (0)