relax

Finished
1//
2// This is only a SKELETON file for the 'Triangle' exercise. It's been provided as a
3// convenience to get you started writing code faster.
4//
5
61export class Triangle {
72 /**
8 * @param {...number} sides
3 * Creates a Triangle instance with the given side lengths.
4 * @param {...number} sides - The lengths of the three sides of the triangle.
95 */
106 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
7 if (sides.length !== 3) {
8 throw new Error('A triangle must have exactly 3 sides');
9 }
10 this.sides = sides;
1211 }
1312
1413 /**
15 * @returns {boolean}
14 * Checks if the triangle is equilateral (all sides equal).
15 * @returns {boolean} True if the triangle is equilateral, false otherwise.
16 * Handled Edge Cases: non-triangle inputs, sides with zero or negative values, invalid triangle inequality
1617 */
1718 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
19 // Edge Case: Check if it's a valid triangle first
20 if (!this._isValidTriangle()) {
21 return false;
22 }
23
24 const [a, b, c] = this.sides;
25 return a === b && b === c;
1926 }
2027
2128 /**
22 * @returns {boolean}
29 * Checks if the triangle is isosceles (at least two sides equal).
30 * @returns {boolean} True if the triangle is isosceles, false otherwise.
31 * Handled Edge Cases: non-triangle inputs, sides with zero or negative values, invalid triangle inequality
2332 */
2433 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
34 // Edge Case: Check if it's a valid triangle first
35 if (!this._isValidTriangle()) {
36 return false;
37 }
38
39 const [a, b, c] = this.sides;
40 return a === b || b === c || a === c;
2641 }
2742
2843 /**
29 * @returns {boolean}
44 * Checks if the triangle is scalene (all sides different).
45 * @returns {boolean} True if the triangle is scalene, false otherwise.
46 * Handled Edge Cases: non-triangle inputs, sides with zero or negative values, invalid triangle inequality
3047 */
3148 get isScalene() {
32 throw new Error('Remove this line and implement the function');
49 // Edge Case: Check if it's a valid triangle first
50 if (!this._isValidTriangle()) {
51 return false;
52 }
53
54 const [a, b, c] = this.sides;
55 return a !== b && b !== c && a !== c;
56 }
57
58 /**
59 * Validates if the sides form a valid triangle.
60 * @returns {boolean} True if valid triangle, false otherwise.
61 * Handled Edge Cases: sides with zero or negative values, invalid triangle inequality
62 */
63 _isValidTriangle() {
64 const [a, b, c] = this.sides;
65
66 // Edge Case: All sides must have positive length
67 if (a <= 0 || b <= 0 || c <= 0) {
68 return false;
69 }
70
71 // Edge Case: Triangle inequality must hold
72 if (a + b < c || b + c < a || a + c < b) {
73 return false;
74 }
75
76 return true;
3377 }
3478}
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.