| 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 | this.sides = sides; |
| 12 | 24 | } |
| 13 | 25 | |
| 14 | 26 | /** |
| 15 | 27 | * @returns {boolean} |
| 16 | 28 | */ |
| 17 | 29 | get isEquilateral() { |
| 18 | | throw new Error('Remove this line and implement the function'); |
| 30 | const [a, b, c] = this.sides; |
| 31 | |
| 32 | // Edge Case: Check if all sides are positive |
| 33 | if (a <= 0 || b <= 0 || c <= 0) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | // Edge Case: Check triangle inequality |
| 38 | if (!(a + b >= c && b + c >= a && a + c >= b)) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | return a === b && b === c; |
| 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 | const [a, b, c] = this.sides; |
| 50 | |
| 51 | // Edge Case: Check if all sides are positive |
| 52 | if (a <= 0 || b <= 0 || c <= 0) { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | // Edge Case: Check triangle inequality |
| 57 | if (!(a + b >= c && b + c >= a && a + c >= b)) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | return a === b || b === c || a === c; |
| 26 | 62 | } |
| 27 | 63 | |
| 28 | 64 | /** |
| 29 | 65 | * @returns {boolean} |
| 30 | 66 | */ |
| 31 | 67 | get isScalene() { |
| 32 | | throw new Error('Remove this line and implement the function'); |
| 68 | const [a, b, c] = this.sides; |
| 69 | |
| 70 | // Edge Case: Check if all sides are positive |
| 71 | if (a <= 0 || b <= 0 || c <= 0) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | // Edge Case: Check triangle inequality |
| 76 | if (!(a + b >= c && b + c >= a && a + c >= b)) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | return a !== b && b !== c && a !== c; |
| 33 | 81 | } |
| 34 | 82 | } |