| 8 | 8 | * @param {...number} sides |
| 9 | 9 | */ |
| 10 | 10 | constructor(...sides) { |
| 11 | | throw new Error('Remove this line and implement the function'); |
| 11 | // Edge Case: Ensure exactly three sides are provided |
| 12 | if (sides.length !== 3) { |
| 13 | throw new Error('Triangle must have exactly three sides'); |
| 14 | } |
| 15 | |
| 16 | // Edge Case: Ensure all sides are numbers |
| 17 | if (sides.some(side => typeof side !== 'number')) { |
| 18 | throw new Error('All sides must be numbers'); |
| 19 | } |
| 20 | |
| 21 | this.sides = sides; |
| 12 | 22 | } |
| 13 | 23 | |
| 14 | 24 | /** |
| 15 | 25 | * @returns {boolean} |
| 16 | 26 | */ |
| 17 | 27 | get isEquilateral() { |
| 18 | | throw new Error('Remove this line and implement the function'); |
| 28 | // Edge Case: Check if it's a valid triangle first |
| 29 | if (!this._isValidTriangle()) { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | const [a, b, c] = this.sides; |
| 34 | return a === b && b === c; |
| 19 | 35 | } |
| 20 | 36 | |
| 21 | 37 | /** |
| 22 | 38 | * @returns {boolean} |
| 23 | 39 | */ |
| 24 | 40 | get isIsosceles() { |
| 25 | | throw new Error('Remove this line and implement the function'); |
| 41 | // Edge Case: Check if it's a valid triangle first |
| 42 | if (!this._isValidTriangle()) { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | const [a, b, c] = this.sides; |
| 47 | return a === b || b === c || a === c; |
| 26 | 48 | } |
| 27 | 49 | |
| 28 | 50 | /** |
| 29 | 51 | * @returns {boolean} |
| 30 | 52 | */ |
| 31 | 53 | get isScalene() { |
| 32 | | throw new Error('Remove this line and implement the function'); |
| 54 | // Edge Case: Check if it's a valid triangle first |
| 55 | if (!this._isValidTriangle()) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | const [a, b, c] = this.sides; |
| 60 | return a !== b && b !== c && a !== c; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Helper method to check if the sides form a valid triangle |
| 65 | * @returns {boolean} |
| 66 | */ |
| 67 | _isValidTriangle() { |
| 68 | const [a, b, c] = this.sides; |
| 69 | |
| 70 | // Edge Case: All sides must have positive length |
| 71 | if (a <= 0 || b <= 0 || c <= 0) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | // Edge Case: Triangle inequality must be satisfied |
| 76 | if ((a + b < c) || (b + c < a) || (a + c < b)) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | return true; |
| 33 | 81 | } |
| 34 | 82 | } |
| 83 | |
| 84 | // Handled Edge Cases: |
| 85 | // - Ensuring exactly three sides are provided |
| 86 | // - Ensuring all sides are numbers |
| 87 | // - Checking for valid triangle (positive sides and triangle inequality) |
| 88 | // - Equilateral triangle check |
| 89 | // - Isosceles triangle check |
| 90 | // - Scalene triangle check |