You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,12 @@
8
8
// write one test at a time, and make it pass, build your solution up methodically
9
9
10
10
functionisProperFraction(numerator,denominator){
11
-
if(numerator<denominator){
11
+
if(Math.abs(numerator)<Math.abs(denominator)){
12
12
returntrue;
13
13
}
14
+
elseif(numerator>=denominator){
15
+
returnfalse;
16
+
}
14
17
}
15
18
16
19
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,29 +34,38 @@ function assertEquals(actualOutput, targetOutput) {
31
34
// Input: numerator = 2, denominator = 3
32
35
// target output: true
33
36
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
37
+
34
38
constproperFraction=isProperFraction(2,3);
35
39
assertEquals(properFraction,true);
36
40
37
41
// Improper Fraction check:
38
42
// Input: numerator = 5, denominator = 2
39
43
// target output: false
40
44
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
45
+
46
+
41
47
constimproperFraction=isProperFraction(5,2);
42
48
assertEquals(improperFraction,false);
43
49
44
50
// Negative Fraction check:
45
51
// Input: numerator = -4, denominator = 7
46
52
// target output: true
47
53
// 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.
54
+
55
+
48
56
constnegativeFraction=isProperFraction(-4,7);
49
-
// ====> complete with your assertion
57
+
assertEquals(negativeFraction,true);
50
58
51
59
// Equal Numerator and Denominator check:
52
60
// Input: numerator = 3, denominator = 3
53
61
// target output: false
54
62
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
0 commit comments