-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path2-is-proper-fraction.js
More file actions
31 lines (25 loc) · 896 Bytes
/
2-is-proper-fraction.js
File metadata and controls
31 lines (25 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function isProperFraction(numerator, denominator) {
if (denominator === 0) return false;
return Math.abs(numerator) < Math.abs(denominator);
}
module.exports = isProperFraction;
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
// Proper fractions
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(2, 3), true);
assertEquals(isProperFraction(7, 10), true);
// Improper fractions
assertEquals(isProperFraction(3, 2), false);
assertEquals(isProperFraction(5, 5), false);
// Negative fractions (still proper)
assertEquals(isProperFraction(-1, 2), true);
assertEquals(isProperFraction(1, -2), true);
assertEquals(isProperFraction(-3, -4), true);
// Zero cases
assertEquals(isProperFraction(0, 2), true);
assertEquals(isProperFraction(1, 0), false);