lexicon

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, all sides equal, not all sides equal
1625 */
1726 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
27 // Edge Case: Not a valid triangle (sides <= 0 or violate triangle inequality)
28 if (!this._isValidTriangle()) {
29 return false;
30 }
31
32 const [a, b, c] = this.sides;
33
34 // Edge Case: All sides are equal
35 return a === b && b === c;
1936 }
2037
2138 /**
22 * @returns {boolean}
39 * Checks if the triangle is isosceles (at least two sides equal).
40 * @returns {boolean} True if the triangle is isosceles, false otherwise.
41 * Handled Edge Cases: Invalid triangle, at least two sides equal, no sides equal
2342 */
2443 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
44 // Edge Case: Not a valid triangle (sides <= 0 or violate triangle inequality)
45 if (!this._isValidTriangle()) {
46 return false;
47 }
48
49 const [a, b, c] = this.sides;
50
51 // Edge Case: At least two sides are equal
52 return a === b || b === c || a === c;
2653 }
2754
2855 /**
29 * @returns {boolean}
56 * Checks if the triangle is scalene (all sides different).
57 * @returns {boolean} True if the triangle is scalene, false otherwise.
58 * Handled Edge Cases: Invalid triangle, all sides different, some sides equal
3059 */
3160 get isScalene() {
32 throw new Error('Remove this line and implement the function');
61 // Edge Case: Not a valid triangle (sides <= 0 or violate triangle inequality)
62 if (!this._isValidTriangle()) {
63 return false;
64 }
65
66 const [a, b, c] = this.sides;
67
68 // Edge Case: All sides are different
69 return a !== b && b !== c && a !== c;
70 }
71
72 /**
73 * Helper method to validate if the sides form a valid triangle.
74 * @returns {boolean} True if valid triangle, false otherwise.
75 * Handled Edge Cases: Sides <= 0, triangle inequality violation
76 */
77 _isValidTriangle() {
78 // Edge Case: Not exactly 3 sides
79 if (this.sides.length !== 3) {
80 return false;
81 }
82
83 const [a, b, c] = this.sides;
84
85 // Edge Case: Any side has length <= 0
86 if (a <= 0 || b <= 0 || c <= 0) {
87 return false;
88 }
89
90 // Edge Case: Violation of triangle inequality (sum of any two sides must be >= third side)
91 if (a + b < c || b + c < a || a + c < b) {
92 return false;
93 }
94
95 return true;
3396 }
3497}
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.