-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path2-is-proper-fraction.js
More file actions
30 lines (22 loc) · 827 Bytes
/
2-is-proper-fraction.js
File metadata and controls
30 lines (22 loc) · 827 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
function isProperFraction(numerator, denominator) {
// Return non numeric numerators and denominators as false
if (typeof numerator != "number" || typeof denominator != "number")
return false;
if (numerator === 0 || 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}`
);
}
// Positive proper fraction test
assertEquals(isProperFraction(1, 2), true);
// Improper proper fraction test
assertEquals(isProperFraction(3, 2), false);
// Negative proper fraction test
assertEquals(isProperFraction(-1, 2), true);
// Zero numerator test
assertEquals(isProperFraction(0, 2), false);