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