| 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 | // Edge Case: Ensure all sides are positive |
| 22 | if (sides.some(side => side <= 0)) { |
| 23 | this.isValid = false; |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | const [a, b, c] = sides; |
| 28 | |
| 29 | // Edge Case: Check triangle inequality theorem |
| 30 | if (a + b < c || b + c < a || a + c < b) { |
| 31 | this.isValid = false; |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | this.sides = sides; |
| 36 | this.isValid = true; |
| 12 | 37 | } |
| 13 | 38 | |
| 14 | 39 | /** |
| 15 | 40 | * @returns {boolean} |
| 16 | 41 | */ |
| 17 | 42 | get isEquilateral() { |
| 18 | | throw new Error('Remove this line and implement the function'); |
| 43 | // Edge Case: Invalid triangle |
| 44 | if (!this.isValid) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | const [a, b, c] = this.sides; |
| 49 | return a === b && b === c; |
| 19 | 50 | } |
| 20 | 51 | |
| 21 | 52 | /** |
| 22 | 53 | * @returns {boolean} |
| 23 | 54 | */ |
| 24 | 55 | get isIsosceles() { |
| 25 | | throw new Error('Remove this line and implement the function'); |
| 56 | // Edge Case: Invalid triangle |
| 57 | if (!this.isValid) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | const [a, b, c] = this.sides; |
| 62 | return a === b || b === c || a === c; |
| 26 | 63 | } |
| 27 | 64 | |
| 28 | 65 | /** |
| 29 | 66 | * @returns {boolean} |
| 30 | 67 | */ |
| 31 | 68 | get isScalene() { |
| 32 | | throw new Error('Remove this line and implement the function'); |
| 69 | // Edge Case: Invalid triangle |
| 70 | if (!this.isValid) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | const [a, b, c] = this.sides; |
| 75 | return a !== b && b !== c && a !== c; |
| 33 | 76 | } |
| 34 | 77 | } |
| 78 | |
| 79 | // Handled Edge Cases: |
| 80 | // 1. Ensure exactly three sides are provided |
| 81 | // 2. Ensure all sides are numbers |
| 82 | // 3. Ensure all sides are positive |
| 83 | // 4. Check triangle inequality theorem |
| 84 | // 5. Invalid triangle for all type checks |
| 85 | // 6. Equilateral triangle check |
| 86 | // 7. Isosceles triangle check |
| 87 | // 8. Scalene triangle check |