Advertisement
elena1234

Work with map and sort, and with complicated object ( JavaScript )

Dec 3rd, 2021
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let result = input.map(([width, height]) => {
  3.       return rectangle = {
  4.             width,
  5.             height,
  6.             area: () => width * height,
  7.             compareTo(other) {
  8.                 return (other.area() - this.area()) || (other.width - this.width);
  9.             }
  10.         }
  11.     }).sort((a, b) => a.compareTo(b));
  12.  
  13.     return (result);
  14. };
  15.  
  16. solve([[10,5], [3,20], [5,12]]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement