Skip to content

Commit 3ba6e74

Browse files
committed
isProperFraction easy estructured
1 parent 48e6a8c commit 3ba6e74

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Sprint-3/implement/is-proper-fraction.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,32 @@
2525
// Negative Fraction check:
2626
// Input: numerator = -4, denominator = 7
2727
// target output: true
28-
// 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.
28+
// Explanation: The fraction -4/7 is a proper fraction because
29+
// the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
2930

3031
// Equal Numerator and Denominator check:
3132
// Input: numerator = 3, denominator = 3
3233
// target output: false
3334
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
3435
// These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator.
36+
37+
function isProperFraction(numerator, denominator) {
38+
// Check for denominator being zero
39+
if (denominator === 0) {
40+
throw new Error("Denominator cannot be zero");
41+
}
42+
43+
// If numerator is equal to denominator, it's not a proper fraction
44+
if (numerator === denominator) {
45+
return false;
46+
}
47+
48+
// Proper fraction if the absolute value of the numerator is less than the denominator
49+
return Math.abs(numerator) < denominator;
50+
}
51+
52+
53+
console.log(isProperFraction(3, 6));
54+
console.log(isProperFraction(-3, 6));
55+
console.log(isProperFraction(9, 0));
56+
console.log(isProperFraction(5, 5));

0 commit comments

Comments
 (0)