File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -5,27 +5,43 @@ class Triangle {
5
5
this . c = c ;
6
6
}
7
7
8
- kind ( ) {
8
+ isValidTriangle ( ) {
9
9
if ( this . a + this . b + this . c <= 0 ) {
10
- throw new Error ( ) ;
10
+ return false ;
11
11
}
12
12
13
13
if ( this . a < 0 || this . b < 0 || this . c < 0 ) {
14
- throw new Error ( ) ;
14
+ return false ;
15
15
}
16
16
17
17
if (
18
18
this . a + this . b < this . c ||
19
19
this . a + this . c < this . b ||
20
20
this . b + this . c < this . a
21
21
) {
22
- throw new Error ( ) ;
22
+ return false ;
23
23
}
24
24
25
- if ( this . a === this . b && this . b === this . c ) {
25
+ return true ;
26
+ }
27
+
28
+ isEquilateral ( ) {
29
+ return this . a === this . b && this . b === this . c ;
30
+ }
31
+
32
+ isIsosceles ( ) {
33
+ return this . a === this . b || this . a === this . c || this . b === this . c ;
34
+ }
35
+
36
+ kind ( ) {
37
+ if ( ! this . isValidTriangle ( ) ) {
38
+ throw new Error ( ) ;
39
+ }
40
+ if ( this . isEquilateral ( ) ) {
26
41
return 'equilateral' ;
27
42
}
28
- if ( this . a === this . b || this . a === this . c || this . b === this . c ) {
43
+
44
+ if ( this . isIsosceles ( ) ) {
29
45
return 'isosceles' ;
30
46
}
31
47
return 'scalene' ;
You can’t perform that action at this time.
0 commit comments