Skip to content

Commit e15fb84

Browse files
committed
Implement isProperFraction function and add corresponding tests
1 parent d28f26f commit e15fb84

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

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

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

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (denominator === 0) {
16+
return false;
17+
}
18+
if (numerator === 0) {
19+
return true;
20+
}
21+
if (numerator < 0 && denominator < 0) {
22+
return isProperFraction(-numerator, -denominator);
23+
}
24+
if (numerator < 0 || denominator < 0) {
25+
return false;
26+
}
27+
return numerator < denominator;
1528
}
1629

1730
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +44,15 @@ function assertEquals(actualOutput, targetOutput) {
3144

3245
// Example: 1/2 is a proper fraction
3346
assertEquals(isProperFraction(1, 2), true);
47+
48+
assertEquals(isProperFraction(2, 1), false);
49+
50+
assertEquals(isProperFraction(0, 1), true);
51+
52+
assertEquals(isProperFraction(1, 0), false);
53+
54+
assertEquals(isProperFraction(-1, 2), true);
55+
56+
assertEquals(isProperFraction(1, -2), false);
57+
58+
assertEquals(isProperFraction(-1, -2), true);

0 commit comments

Comments
 (0)