Skip to content

Commit 258000e

Browse files
committed
Implement isProperFraction function
1 parent 12ae68f commit 258000e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
// Implement a function isProperFraction
22
// Write assertions for your function to check it works in different cases
3-
// Terms:
3+
// Terms:A proper fraction is when:
4+
//the absolute value of the numerator is less than the denominator
5+
46
// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j
57
// Written here like this: 1/2 == Numerator/Denominator
68
// the first test and first case is written for you
7-
// complete the rest of the tests and cases
8-
// write one test at a time, and make it pass, build your solution up methodically
9+
// 1-complete the rest of the tests and cases
910

11+
// 2-write one test at a time, and make it pass, build your solution up methodically
12+
//1-
1013
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
14+
if (Math.abs(numerator) < Math.abs(denominator)) {
1215
return true;
16+
} else {
17+
return false;
1318
}
1419
}
1520

@@ -46,14 +51,20 @@ assertEquals(improperFraction, false);
4651
// target output: true
4752
// 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.
4853
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
54+
assertEquals(negativeFraction, true);
55+
5056

5157
// Equal Numerator and Denominator check:
5258
// Input: numerator = 3, denominator = 3
5359
// target output: false
5460
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5561
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
62+
assertEquals(equalFraction, false);
63+
64+
5765

5866
// Stretch:
5967
// What other scenarios could you test for?
68+
const negativeDenominator = isProperFraction(3, -5);
69+
assertEquals(negativeDenominator, true);
70+
const bothNegative = isProperFraction(-2, -6);

0 commit comments

Comments
 (0)