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