Skip to content

Commit fb6c731

Browse files
committed
Add toString method
1 parent 4052a59 commit fb6c731

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

JavaScript/8-geometry.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ class Point {
55
this.x = x;
66
this.y = y;
77
}
8+
9+
toString() {
10+
return `(${this.x}, ${this.y})`;
11+
}
812
}
913

1014
class Polygon {
@@ -21,6 +25,10 @@ class Polygon {
2125
}
2226
return Math.abs(value) / 2;
2327
}
28+
29+
toString() {
30+
return this.points.map((p) => p.toString()).join('; ');
31+
}
2432
}
2533

2634
class Rect extends Polygon {
@@ -73,3 +81,4 @@ console.log('Rotate 90');
7381
Geometry.rotate(triangle, 90);
7482
console.dir(triangle);
7583
console.dir(triangle.area);
84+
console.dir(`${triangle}`);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy