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
+8-16Lines changed: 8 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,10 @@
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){
12
-
returntrue;
11
+
if(Math.abs(numerator)<Math.abs(denominator)){
12
+
returntrue;// <-- answer
13
13
}
14
+
returnfalse;// <-- answer
14
15
}
15
16
16
17
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -28,32 +29,23 @@ function assertEquals(actualOutput, targetOutput) {
28
29
// Acceptance criteria:
29
30
30
31
// Proper Fraction check:
31
-
// Input: numerator = 2, denominator = 3
32
-
// target output: true
33
-
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
34
32
constproperFraction=isProperFraction(2,3);
35
33
assertEquals(properFraction,true);
36
34
37
35
// Improper Fraction check:
38
-
// Input: numerator = 5, denominator = 2
39
-
// target output: false
40
-
// 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.
41
36
constimproperFraction=isProperFraction(5,2);
42
37
assertEquals(improperFraction,false);
43
38
44
39
// Negative Fraction check:
45
-
// Input: numerator = -4, denominator = 7
46
-
// target output: true
47
-
// 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.
48
40
constnegativeFraction=isProperFraction(-4,7);
49
-
// ====> complete with your assertion
41
+
assertEquals(negativeFraction,true);// <-- answer
50
42
51
43
// Equal Numerator and Denominator check:
52
-
// Input: numerator = 3, denominator = 3
53
-
// target output: false
54
-
// 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