Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. function orderRectangles(data) {
  2. let rects = [];
  3. for(let [widht, height] of data){
  4. let rect = createRect(widht, height);
  5. rects.push(rect);
  6. }
  7.  
  8. let bigRect = rects.sort((a, b)=> a.compareTo(b));
  9. return bigRect;
  10.  
  11. function createRect(width, height) {
  12. let rect = {
  13. width: width,
  14. height: height,
  15. area: ()=> rect.width * rect.height,
  16. compareTo: function (other) {
  17. let result = other.area() - rect.area();
  18. return result || (other.width - rect.width);
  19. }
  20. };
  21. return rect;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement