Skip to content

Commit 35c3083

Browse files
Refactor isProperFraction function to handle NaN inputs and improve logic for proper fraction checks
1 parent 366621c commit 35c3083

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11+
1112
if (Math.abs(numerator) < Math.abs(denominator)) {
1213
return true;
1314
}
@@ -17,9 +18,10 @@ function isProperFraction(numerator, denominator) {
1718
) {
1819
return false;
1920
}
20-
if(Number.isNaN(numerator) || Number.isNaN(denominator)){
21-
throw new Error("Not a number")
21+
if (typeof numerator === "number" && typeof denominator === "number") {
22+
return true;
2223
}
24+
2325
}
2426

2527
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -88,5 +90,5 @@ assertEquals(negativeDenominator,true)
8890

8991

9092
//got stuck on this one, don't know how to test
91-
// const notANumber=isProperFraction("a",2)
92-
// assertEquals(negativeFraction, "Not a number");
93+
const notANumber=isProperFraction("a",2)
94+
assertEquals(notANumber,false);

0 commit comments

Comments
 (0)