Skip to content

Commit 6825f69

Browse files
i786mDias, Diego
authored andcommitted
Implemented a function isProperFraction
1 parent fdc0069 commit 6825f69

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
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) {
11+
if (Math.abs(numerator) < Math.abs(denominator)) {
1212
return true;
1313
}
14+
if (numerator >= denominator) {
15+
return false;
16+
}
17+
if(numerator == 0){
18+
return true;
19+
}
20+
if (denominator === 0) {
21+
return false;
22+
}
1423
}
1524

1625
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -47,13 +56,48 @@ assertEquals(improperFraction, false);
4756
// 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.
4857
const negativeFraction = isProperFraction(-4, 7);
4958
// ====> complete with your assertion
50-
59+
assertEquals(negativeFraction, true);
5160
// Equal Numerator and Denominator check:
5261
// Input: numerator = 3, denominator = 3
5362
// target output: false
5463
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5564
const equalFraction = isProperFraction(3, 3);
5665
// ====> complete with your assertion
57-
66+
assertEquals(equalFraction, false);
5867
// Stretch:
5968
// What other scenarios could you test for?
69+
// Zero Numerator check:
70+
// Input: numerator = 0, denominator = 5
71+
// target output: true
72+
// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true.
73+
const zeroNumerator = isProperFraction(0, 5);
74+
// ====> complete with your assertion
75+
assertEquals(zeroNumerator, true);
76+
// Zero Denominator check:
77+
// Input: numerator = 4, denominator = 0
78+
// target output: false
79+
// Explanation: The fraction 4/0 is undefined because division by zero is not allowed. The function should return false.
80+
const zeroDenominator = isProperFraction(4, 0);
81+
// ====> complete with your assertion
82+
assertEquals(zeroDenominator, false);
83+
// Negative Denominator check:
84+
// Input: numerator = 3, denominator = -5
85+
// target output: true
86+
// Explanation: The fraction 3/-5 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (5). The function should return true.
87+
const negativeDenominator = isProperFraction(3, -5);
88+
// ====> complete with your assertion
89+
assertEquals(negativeDenominator, true);
90+
// Both Negative check:
91+
// Input: numerator = -2, denominator = -6
92+
// target output: true
93+
// Explanation: The fraction -2/-6 is a proper fraction because the absolute value of the numerator (2) is less than the absolute value of the denominator (6). The function should return true.
94+
const bothNegative = isProperFraction(-2, -6);
95+
// ====> complete with your assertion
96+
assertEquals(bothNegative, true);
97+
// Zero Numerator and Denominator check:
98+
// Input: numerator = 0, denominator = 0
99+
// target output: false
100+
// Explanation: The fraction 0/0 is undefined. The function should return false.
101+
const zeroNumeratorDenominator = isProperFraction(0, 0);
102+
// ====> complete with your assertion
103+
assertEquals(zeroNumeratorDenominator, false);

0 commit comments

Comments
 (0)