| 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 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 by converting to numbers |
| 18 | this.sides = sides.map(side => Number(side)); |
| 12 | 19 | } |
| 13 | 20 | |
| 14 | 21 | /** |
| 15 | 22 | * @returns {boolean} |
| 16 | 23 | */ |
| 17 | 24 | get isEquilateral() { |
| 18 | | throw new Error('Remove this line and implement the function'); |
| 25 | const [a, b, c] = this.sides; |
| 26 | |
| 27 | // Edge Case: Check for invalid triangle (zero or negative sides) |
| 28 | if (a <= 0 || b <= 0 || c <= 0) { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | // Edge Case: Check triangle inequality |
| 33 | if (a + b <= c || b + c <= a || a + c <= b) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | // Edge Case: All sides must be equal for equilateral |
| 38 | return a === b && b === c; |
| 39 | // Handled Edge Cases: invalid sides, triangle inequality violation, equal sides check |
| 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 | const [a, b, c] = this.sides; |
| 47 | |
| 48 | // Edge Case: Check for invalid triangle (zero or negative sides) |
| 49 | if (a <= 0 || b <= 0 || c <= 0) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | // Edge Case: Check triangle inequality |
| 54 | if (a + b <= c || b + c <= a || a + c <= b) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | // Edge Case: At least two sides must be equal for isosceles |
| 59 | return a === b || b === c || a === c; |
| 60 | // Handled Edge Cases: invalid sides, triangle inequality violation, equal sides check |
| 26 | 61 | } |
| 27 | 62 | |
| 28 | 63 | /** |
| 29 | 64 | * @returns {boolean} |
| 30 | 65 | */ |
| 31 | 66 | get isScalene() { |
| 32 | | throw new Error('Remove this line and implement the function'); |
| 67 | const [a, b, c] = this.sides; |
| 68 | |
| 69 | // Edge Case: Check for invalid triangle (zero or negative sides) |
| 70 | if (a <= 0 || b <= 0 || c <= 0) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | // Edge Case: Check triangle inequality |
| 75 | if (a + b <= c || b + c <= a || a + c <= b) { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | // Edge Case: All sides must be different for scalene |
| 80 | return a !== b && b !== c && a !== c; |
| 81 | // Handled Edge Cases: invalid sides, triangle inequality violation, unequal sides check |
| 33 | 82 | } |
| 34 | 83 | } |