weekends

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: Incorrect number of sides provided
13 if (sides.length !== 3) {
14 this.sides = [];
15 return;
16 }
17 this.sides = sides;
1218 }
1319
1420 /**
15 * @returns {boolean}
21 * Checks if the triangle is equilateral (all sides equal).
22 * @returns {boolean} True if the triangle is equilateral, false otherwise.
23 * Handled Edge Cases: Invalid triangle, all sides equal
1624 */
1725 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
26 // Edge Case: Not a valid triangle
27 if (!this._isValidTriangle()) {
28 return false;
29 }
30
31 const [a, b, c] = this.sides;
32 return a === b && b === c;
1933 }
2034
2135 /**
22 * @returns {boolean}
36 * Checks if the triangle is isosceles (at least two sides equal).
37 * @returns {boolean} True if the triangle is isosceles, false otherwise.
38 * Handled Edge Cases: Invalid triangle, at least two sides equal
2339 */
2440 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
41 // Edge Case: Not a valid triangle
42 if (!this._isValidTriangle()) {
43 return false;
44 }
45
46 const [a, b, c] = this.sides;
47 return a === b || b === c || a === c;
2648 }
2749
2850 /**
29 * @returns {boolean}
51 * Checks if the triangle is scalene (all sides different).
52 * @returns {boolean} True if the triangle is scalene, false otherwise.
53 * Handled Edge Cases: Invalid triangle, all sides different
3054 */
3155 get isScalene() {
32 throw new Error('Remove this line and implement the function');
56 // Edge Case: Not a valid triangle
57 if (!this._isValidTriangle()) {
58 return false;
59 }
60
61 const [a, b, c] = this.sides;
62 return a !== b && b !== c && a !== c;
63 }
64
65 /**
66 * Validates if the sides form a valid triangle.
67 * @returns {boolean} True if valid triangle, false otherwise.
68 * Handled Edge Cases: Zero or negative sides, triangle inequality violation
69 */
70 _isValidTriangle() {
71 // Edge Case: Not exactly three sides
72 if (this.sides.length !== 3) {
73 return false;
74 }
75
76 const [a, b, c] = this.sides;
77
78 // Edge Case: Sides with zero or negative length
79 if (a <= 0 || b <= 0 || c <= 0) {
80 return false;
81 }
82
83 // Edge Case: Violation of triangle inequality
84 if (a + b < c || b + c < a || a + c < b) {
85 return false;
86 }
87
88 return true;
3389 }
3490}
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.