yahoo

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 throw new Error('A triangle must have exactly 3 sides');
15 }
16
17 // Edge Case: Non-numeric side lengths
18 if (sides.some(side => typeof side !== 'number')) {
19 throw new Error('All sides must be numbers');
20 }
21
22 this.sides = sides;
1223 }
1324
1425 /**
15 * @returns {boolean}
26 * Checks if the triangle is valid according to triangle inequality rules.
27 * A valid triangle has all sides > 0 and sum of any two sides >= third side.
28 * @returns {boolean} True if the triangle is valid, false otherwise.
29 * Handled Edge Cases: sides <= 0, triangle inequality violation
30 */
31 isValidTriangle() {
32 const [a, b, c] = this.sides;
33
34 // Edge Case: Any side has length <= 0
35 if (a <= 0 || b <= 0 || c <= 0) {
36 return false;
37 }
38
39 // Edge Case: Triangle inequality violation (sum of any two sides must be >= third side)
40 if ((a + b < c) || (b + c < a) || (a + c < b)) {
41 return false;
42 }
43
44 return true;
45 }
46
47 /**
48 * Determines if the triangle is equilateral (all sides equal).
49 * @returns {boolean} True if the triangle is equilateral, false otherwise.
50 * Handled Edge Cases: invalid triangle
1651 */
1752 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
53 // Edge Case: Invalid triangle
54 if (!this.isValidTriangle()) {
55 return false;
56 }
57
58 const [a, b, c] = this.sides;
59 return a === b && b === c;
1960 }
2061
2162 /**
22 * @returns {boolean}
63 * Determines if the triangle is isosceles (at least two sides equal).
64 * @returns {boolean} True if the triangle is isosceles, false otherwise.
65 * Handled Edge Cases: invalid triangle
2366 */
2467 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
68 // Edge Case: Invalid triangle
69 if (!this.isValidTriangle()) {
70 return false;
71 }
72
73 const [a, b, c] = this.sides;
74 return a === b || b === c || a === c;
2675 }
2776
2877 /**
29 * @returns {boolean}
78 * Determines if the triangle is scalene (all sides different).
79 * @returns {boolean} True if the triangle is scalene, false otherwise.
80 * Handled Edge Cases: invalid triangle
3081 */
3182 get isScalene() {
32 throw new Error('Remove this line and implement the function');
83 // Edge Case: Invalid triangle
84 if (!this.isValidTriangle()) {
85 return false;
86 }
87
88 const [a, b, c] = this.sides;
89 return a !== b && b !== c && a !== c;
3390 }
3491}
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.