couple

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 triangle's sides.
5 * @throws {Error} If the number of sides is not exactly three.
96 */
107 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
8 if (sides.length !== 3) {
9 throw new Error('A triangle must have exactly three sides');
10 }
11 this.sides = sides;
1212 }
1313
1414 /**
15 * @returns {boolean}
15 * Checks if the triangle is equilateral (all sides equal).
16 * @returns {boolean} True if the triangle is equilateral, false otherwise.
17 * Handled Edge Cases: invalid triangle, all sides equal
1618 */
1719 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
20 // Edge Case: Invalid triangle (sides <= 0 or violate triangle inequality)
21 if (!this._isValidTriangle()) {
22 return false;
23 }
24
25 const [a, b, c] = this.sides;
26 return a === b && b === c;
27 // Handled Edge Cases: invalid triangle, all sides equal
1928 }
2029
2130 /**
22 * @returns {boolean}
31 * Checks if the triangle is isosceles (at least two sides equal).
32 * @returns {boolean} True if the triangle is isosceles, false otherwise.
33 * Handled Edge Cases: invalid triangle, at least two sides equal
2334 */
2435 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
36 // Edge Case: Invalid triangle (sides <= 0 or violate triangle inequality)
37 if (!this._isValidTriangle()) {
38 return false;
39 }
40
41 const [a, b, c] = this.sides;
42 return a === b || b === c || a === c;
43 // Handled Edge Cases: invalid triangle, at least two sides equal
2644 }
2745
2846 /**
29 * @returns {boolean}
47 * Checks if the triangle is scalene (all sides different).
48 * @returns {boolean} True if the triangle is scalene, false otherwise.
49 * Handled Edge Cases: invalid triangle, all sides different
3050 */
3151 get isScalene() {
32 throw new Error('Remove this line and implement the function');
52 // Edge Case: Invalid triangle (sides <= 0 or violate triangle inequality)
53 if (!this._isValidTriangle()) {
54 return false;
55 }
56
57 const [a, b, c] = this.sides;
58 return a !== b && b !== c && a !== c;
59 // Handled Edge Cases: invalid triangle, all sides different
60 }
61
62 /**
63 * Validates if the sides form a valid triangle.
64 * All sides must be > 0 and satisfy the triangle inequality.
65 * @returns {boolean} True if valid triangle, false otherwise.
66 * Handled Edge Cases: sides <= 0, triangle inequality violation
67 */
68 _isValidTriangle() {
69 const [a, b, c] = this.sides;
70
71 // Edge Case: Any side is zero or negative
72 if (a <= 0 || b <= 0 || c <= 0) {
73 return false;
74 }
75
76 // Edge Case: Triangle inequality violation
77 if (a + b < c || b + c < a || a + c < b) {
78 return false;
79 }
80
81 return true;
82 // Handled Edge Cases: sides <= 0, triangle inequality violation
3383 }
3484}
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.