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