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