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 triangle's sides.
910 */
1011 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
12 // Edge Case: Invalid number of sides (not exactly 3)
13 if (sides.length !== 3) {
14 this.sides = [];
15 return;
16 }
17
18 this.sides = sides;
1219 }
1320
1421 /**
15 * @returns {boolean}
22 * Checks if the triangle is equilateral (all sides equal).
23 * @returns {boolean} True if the triangle is equilateral, false otherwise.
24 * Handled Edge Cases: Invalid triangle, non-positive sides, inequality violation, all sides equal
1625 */
1726 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
27 // Edge Case: Not enough sides to form a triangle
28 if (this.sides.length !== 3) return false;
29
30 const [a, b, c] = this.sides;
31
32 // Edge Case: Sides with zero or negative length
33 if (a <= 0 || b <= 0 || c <= 0) return false;
34
35 // Edge Case: Triangle inequality violation
36 if (a + b < c || b + c < a || a + c < b) return false;
37
38 // Edge Case: All sides are equal (equilateral condition)
39 return a === b && b === c;
1940 }
2041
2142 /**
22 * @returns {boolean}
43 * Checks if the triangle is isosceles (at least two sides equal).
44 * @returns {boolean} True if the triangle is isosceles, false otherwise.
45 * Handled Edge Cases: Invalid triangle, non-positive sides, inequality violation, at least two sides equal
2346 */
2447 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
48 // Edge Case: Not enough sides to form a triangle
49 if (this.sides.length !== 3) return false;
50
51 const [a, b, c] = this.sides;
52
53 // Edge Case: Sides with zero or negative length
54 if (a <= 0 || b <= 0 || c <= 0) return false;
55
56 // Edge Case: Triangle inequality violation
57 if (a + b < c || b + c < a || a + c < b) return false;
58
59 // Edge Case: At least two sides are equal (isosceles condition)
60 return a === b || b === c || a === c;
2661 }
2762
2863 /**
29 * @returns {boolean}
64 * Checks if the triangle is scalene (all sides different).
65 * @returns {boolean} True if the triangle is scalene, false otherwise.
66 * Handled Edge Cases: Invalid triangle, non-positive sides, inequality violation, all sides different
3067 */
3168 get isScalene() {
32 throw new Error('Remove this line and implement the function');
69 // Edge Case: Not enough sides to form a triangle
70 if (this.sides.length !== 3) return false;
71
72 const [a, b, c] = this.sides;
73
74 // Edge Case: Sides with zero or negative length
75 if (a <= 0 || b <= 0 || c <= 0) return false;
76
77 // Edge Case: Triangle inequality violation
78 if (a + b < c || b + c < a || a + c < b) return false;
79
80 // Edge Case: All sides are different (scalene condition)
81 return a !== b && b !== c && a !== c;
3382 }
3483}
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.