Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(recs) {
- const orderedRecs = [];
- for (let rec of recs) {
- [w, h] = rec;
- orderedRecs.push({
- width: w,
- height: h,
- area: function() { return this.width * this.height},
- compareTo: function(other) {
- return other.area() - this.area() || other.width - this.width;
- }
- });
- }
- orderedRecs.sort((a, b) => a.compareTo(b));
- return orderedRecs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement