Merry

Finished
55
66export class Triangle {
77 /**
8 * @param {...number} sides
8 * Creates a Triangle instance with the given side lengths.
9 * @param {...number} sides - The lengths of the three sides of the triangle.
910 */
1011 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
12 // Edge Case: Invalid number of sides provided
13 if (sides.length !== 3) {
14 throw new Error('A triangle must have exactly 3 sides');
15 }
16
17 // Edge Case: Non-numeric values provided
18 if (sides.some(side => typeof side !== 'number')) {
19 throw new Error('All sides must be numbers');
20 }
21
22 // Edge Case: NaN values provided
23 if (sides.some(side => isNaN(side))) {
24 throw new Error('Sides cannot be NaN');
25 }
26
27 this.sides = sides;
1228 }
1329
1430 /**
15 * @returns {boolean}
31 * Checks if the triangle is equilateral (all sides equal).
32 * @returns {boolean} True if the triangle is equilateral, false otherwise.
33 * Handled Edge Cases: Invalid triangle (sides <= 0, violates triangle inequality), all sides equal
1634 */
1735 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
36 const [a, b, c] = this.sides;
37
38 // Edge Case: Invalid triangle (sides must be > 0)
39 if (a <= 0 || b <= 0 || c <= 0) {
40 return false;
41 }
42
43 // Edge Case: Violates triangle inequality
44 if (a + b < c || b + c < a || a + c < b) {
45 return false;
46 }
47
48 return a === b && b === c;
1949 }
2050
2151 /**
22 * @returns {boolean}
52 * Checks if the triangle is isosceles (at least two sides equal).
53 * @returns {boolean} True if the triangle is isosceles, false otherwise.
54 * Handled Edge Cases: Invalid triangle (sides <= 0, violates triangle inequality), at least two sides equal
2355 */
2456 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
57 const [a, b, c] = this.sides;
58
59 // Edge Case: Invalid triangle (sides must be > 0)
60 if (a <= 0 || b <= 0 || c <= 0) {
61 return false;
62 }
63
64 // Edge Case: Violates triangle inequality
65 if (a + b < c || b + c < a || a + c < b) {
66 return false;
67 }
68
69 return a === b || b === c || a === c;
2670 }
2771
2872 /**
29 * @returns {boolean}
73 * Checks if the triangle is scalene (all sides different).
74 * @returns {boolean} True if the triangle is scalene, false otherwise.
75 * Handled Edge Cases: Invalid triangle (sides <= 0, violates triangle inequality), all sides different
3076 */
3177 get isScalene() {
32 throw new Error('Remove this line and implement the function');
78 const [a, b, c] = this.sides;
79
80 // Edge Case: Invalid triangle (sides must be > 0)
81 if (a <= 0 || b <= 0 || c <= 0) {
82 return false;
83 }
84
85 // Edge Case: Violates triangle inequality
86 if (a + b < c || b + c < a || a + c < b) {
87 return false;
88 }
89
90 return a !== b && b !== c && a !== c;
3391 }
3492}
Test NameStatus
all sides are equal
Pass
any side is unequal
Pass
no sides are equal
Pass
all zero sides is not a triangle
Pass
sides may be floats
Pass
last two sides are equal
Pass
first two sides are equal
Pass
first and last sides are equal
Pass
equilateral triangles are also isosceles
Pass
no sides are equal
Pass
first triangle inequality violation
Pass
second triangle inequality violation
Pass
third triangle inequality violation
Pass
sides may be floats
Pass
no sides are equal
Pass
all sides are equal
Pass
first and second sides are equal
Pass
first and third sides are equal
Pass
second and third sides are equal
Pass
may not violate triangle inequality
Pass
sides may be floats
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.