| 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: Invalid number of sides (not exactly 3) |
| 12 | if (sides.length !== 3) { |
| 13 | throw new Error('Triangle must have exactly 3 sides'); |
| 14 | } |
| 15 | |
| 16 | // Edge Case: Non-numeric sides |
| 17 | if (sides.some(side => typeof side !== 'number')) { |
| 18 | throw new Error('All sides must be numbers'); |
| 19 | } |
| 20 | |
| 21 | // Edge Case: NaN values |
| 22 | if (sides.some(side => isNaN(side))) { |
| 23 | throw new Error('Sides cannot be NaN'); |
| 24 | } |
| 25 | |
| 26 | // Edge Case: Infinite values |
| 27 | if (sides.some(side => !isFinite(side))) { |
| 28 | throw new Error('Sides cannot be infinite'); |
| 29 | } |
| 30 | |
| 31 | this.sides = sides; |
| 12 | 32 | } |
| 13 | 33 | |
| 14 | 34 | /** |
| 15 | 35 | * @returns {boolean} |
| 16 | 36 | */ |
| 17 | 37 | get isEquilateral() { |
| 18 | | throw new Error('Remove this line and implement the function'); |
| 38 | const [a, b, c] = this.sides; |
| 39 | |
| 40 | // Edge Case: All sides must be positive |
| 41 | if (a <= 0 || b <= 0 || c <= 0) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | // Edge Case: Triangle inequality violation |
| 46 | if (!this._isValidTriangle()) { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | return a === b && b === c; |
| 19 | 51 | } |
| 20 | 52 | |
| 21 | 53 | /** |
| 22 | 54 | * @returns {boolean} |
| 23 | 55 | */ |
| 24 | 56 | get isIsosceles() { |
| 25 | | throw new Error('Remove this line and implement the function'); |
| 57 | const [a, b, c] = this.sides; |
| 58 | |
| 59 | // Edge Case: All sides must be positive |
| 60 | if (a <= 0 || b <= 0 || c <= 0) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | // Edge Case: Triangle inequality violation |
| 65 | if (!this._isValidTriangle()) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | return a === b || b === c || a === c; |
| 26 | 70 | } |
| 27 | 71 | |
| 28 | 72 | /** |
| 29 | 73 | * @returns {boolean} |
| 30 | 74 | */ |
| 31 | 75 | get isScalene() { |
| 32 | | throw new Error('Remove this line and implement the function'); |
| 76 | const [a, b, c] = this.sides; |
| 77 | |
| 78 | // Edge Case: All sides must be positive |
| 79 | if (a <= 0 || b <= 0 || c <= 0) { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | // Edge Case: Triangle inequality violation |
| 84 | if (!this._isValidTriangle()) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | return a !== b && b !== c && a !== c; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Helper method to check if the sides form a valid triangle |
| 93 | * @returns {boolean} |
| 94 | */ |
| 95 | _isValidTriangle() { |
| 96 | const [a, b, c] = this.sides; |
| 97 | |
| 98 | // Edge Case: All sides must be positive |
| 99 | if (a <= 0 || b <= 0 || c <= 0) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | // Check triangle inequality: sum of any two sides must be >= third side |
| 104 | return (a + b >= c) && (b + c >= a) && (a + c >= b); |
| 33 | 105 | } |
| 34 | 106 | } |
| 107 | |
| 108 | // Handled Edge Cases: Invalid number of sides, non-numeric sides, NaN values, infinite values, negative or zero sides, triangle inequality violations |
| 109 | // Handled Edge Cases: All sides must be positive, triangle inequality violation |
| 110 | // Handled Edge Cases: All sides must be positive, triangle inequality violation |
| 111 | // Handled Edge Cases: All sides must be positive, triangle inequality violation |