Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function orderRectangles(input) {
- class Rectangle {
- constructor(width, height) {
- this.width = width;
- this.height = height;
- }
- area() {
- return this.width * this.height;
- }
- compareTo(other) {
- return other.area() - this.area() || other.width - this.width;
- }
- }
- const rectangles = [];
- input.forEach((rectangleValues) => {
- const [width, height] = rectangleValues;
- const rectangle = new Rectangle(width, height);
- rectangles.push(rectangle);
- });
- rectangles.sort((a, b) => a.compareTo(b));
- return rectangles;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement