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
// Written here like this: 1/2 == Numerator/Denominator
6
-
// 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
1
+
// Implement a function isProperFraction,
2
+
// when given two numbers, a numerator and a denominator, it should return true if
3
+
// the given numbers form a proper fraction, and false otherwise.
4
+
5
+
// Assumption: The parameters are valid numbers (not NaN or Infinity).
6
+
7
+
// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition.
8
+
9
+
// Acceptance criteria:
10
+
// After you have implemented the function, write tests to cover all the cases, and
11
+
// execute the code to ensure all tests pass.
9
12
10
13
functionisProperFraction(numerator,denominator){
11
-
if(numerator<denominator){
12
-
returntrue;
13
-
}
14
+
// TODO: Implement this function
14
15
}
15
16
16
17
// The line below allows us to load the isProperFraction function into tests in other files.
17
18
// This will be useful in the "rewrite tests with jest" step.
18
19
module.exports=isProperFraction;
19
20
20
-
// here's our helper again
21
+
// Here's our helper again
21
22
functionassertEquals(actualOutput,targetOutput){
22
23
console.assert(
23
24
actualOutput===targetOutput,
24
25
`Expected ${actualOutput} to equal ${targetOutput}`
25
26
);
26
27
}
27
28
28
-
// Acceptance criteria:
29
+
// TODO: Write tests to cover all cases.
30
+
// What combinations of numerators and denominators should you test?
29
31
30
-
// 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
-
constproperFraction=isProperFraction(2,3);
35
-
assertEquals(properFraction,true);
36
-
37
-
// 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
-
constimproperFraction=isProperFraction(5,2);
42
-
assertEquals(improperFraction,false);
43
-
44
-
// 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
-
constnegativeFraction=isProperFraction(-4,7);
49
-
// ====> complete with your assertion
50
-
51
-
// 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