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-key-implement/2-is-proper-fraction.js
+40-5Lines changed: 40 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,11 @@
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)returntrue;
11
+
// A proper fraction has a non-zero denominator,
12
+
// and the absolute value of the numerator is less than the denominator.
13
+
if(denominator===0)returnfalse;
14
+
returnMath.abs(numerator)<Math.abs(denominator);
15
+
12
16
}
13
17
14
18
// here's our helper again
@@ -24,30 +28,61 @@ function assertEquals(actualOutput, targetOutput) {
24
28
// Proper Fraction check:
25
29
// Input: numerator = 2, denominator = 3
26
30
// target output: true
27
-
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
31
+
// Explanation: The fraction 2/3 is a proper fraction, where the numerator
32
+
// is less than the denominator. The function should return true.
28
33
constproperFraction=isProperFraction(2,3);
29
34
assertEquals(properFraction,true);
30
35
31
36
// Improper Fraction check:
32
37
// Input: numerator = 5, denominator = 2
33
38
// target output: false
34
-
// 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.
39
+
// Explanation: The fraction 5/2 is an improper fraction, where the numerator
40
+
// is greater than or equal to the denominator. The function should return false.
35
41
constimproperFraction=isProperFraction(5,2);
36
42
assertEquals(improperFraction,false);
37
43
38
44
// Negative Fraction check:
39
45
// Input: numerator = -4, denominator = 7
40
46
// target output: true
41
-
// 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.
47
+
// Explanation: The fraction -4/7 is a proper fraction because the absolute
48
+
// value of the numerator (4) is less than the denominator (7).
49
+
// The function should return true.
42
50
constnegativeFraction=isProperFraction(-4,7);
51
+
assertEquals(negativeFraction,true);
43
52
// ====> complete with your assertion
44
53
45
54
// Equal Numerator and Denominator check:
46
55
// Input: numerator = 3, denominator = 3
47
56
// target output: false
48
-
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
57
+
// Explanation: The fraction 3/3 is not a proper fraction because the
58
+
// numerator is equal to the denominator. The function should return false.
49
59
constequalFraction=isProperFraction(3,3);
60
+
assertEquals(equalFraction,false);
50
61
// ====> complete with your assertion
51
62
52
63
// Stretch:
53
64
// What other scenarios could you test for?
65
+
// Zero Numerator check:
66
+
// Input: numerator = 0, denominator = 5
67
+
// target output: true
68
+
// Explanation: The fraction 0/5 is a proper fraction because the numerator
69
+
// is less than the denominator. The function should return true.
70
+
constzeroNumerator=isProperFraction(0,5);
71
+
assertEquals(zeroNumerator,true);
72
+
73
+
// Zero Denominator check:
74
+
// Input: numerator = 3, denominator = 0
75
+
// target output: false
76
+
// Explanation: A fraction with a zero denominator is undefined,
77
+
// so the function should return false.
78
+
constzeroDenominator=isProperFraction(3,0);
79
+
assertEquals(zeroDenominator,false);
80
+
81
+
// Negative Denominator check:
82
+
// Input: numerator = 3, denominator = -5
83
+
// target output: true
84
+
// Explanation: The fraction 3/-5 is a proper fraction because the absolute
85
+
// value of the numerator is less than the absolute value of the denominator.
0 commit comments