| 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: Handle when not exactly 3 sides are provided |
| 12 | if (sides.length !== 3) { |
| 13 | this.sides = [0, 0, 0]; |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | // Edge Case: Handle non-numeric values |
| 18 | if (sides.some(side => typeof side !== 'number' || isNaN(side))) { |
| 19 | this.sides = [0, 0, 0]; |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | // Edge Case: Handle infinite or negative values |
| 24 | if (sides.some(side => !isFinite(side) || side <= 0)) { |
| 25 | this.sides = [0, 0, 0]; |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | this.sides = sides; |
| 12 | 30 | } |
| 13 | 31 | |
| 14 | 32 | /** |
| 15 | 33 | * @returns {boolean} |
| 16 | 34 | */ |
| 17 | 35 | get isEquilateral() { |
| 18 | | throw new Error('Remove this line and implement the function'); |
| 36 | const [a, b, c] = this.sides; |
| 37 | |
| 38 | // Edge Case: Handle invalid triangle |
| 39 | if (a <= 0 || b <= 0 || c <= 0) { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | // Edge Case: Handle triangle inequality violation |
| 44 | if (a + b < c || b + c < a || a + c < b) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | return a === b && b === c; |
| 19 | 49 | } |
| 20 | 50 | |
| 21 | 51 | /** |
| 22 | 52 | * @returns {boolean} |
| 23 | 53 | */ |
| 24 | 54 | get isIsosceles() { |
| 25 | | throw new Error('Remove this line and implement the function'); |
| 55 | const [a, b, c] = this.sides; |
| 56 | |
| 57 | // Edge Case: Handle invalid triangle |
| 58 | if (a <= 0 || b <= 0 || c <= 0) { |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | // Edge Case: Handle triangle inequality violation |
| 63 | if (a + b < c || b + c < a || a + c < b) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | return a === b || b === c || a === c; |
| 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 | const [a, b, c] = this.sides; |
| 75 | |
| 76 | // Edge Case: Handle invalid triangle |
| 77 | if (a <= 0 || b <= 0 || c <= 0) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | // Edge Case: Handle triangle inequality violation |
| 82 | if (a + b < c || b + c < a || a + c < b) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | return a !== b && b !== c && a !== c; |
| 33 | 87 | } |
| 34 | 88 | } |
| 89 | |
| 90 | // Handled Edge Cases: zero or negative side lengths, non-numeric values, infinite values, wrong number of sides, triangle inequality violations |