Guest User

Untitled

a guest
Nov 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. const checkBox = (box1, box2) => {
  2.  
  3. const check = (box1, box2) => {
  4.  
  5. if (box1.w >= box2.w && box1.h >= box2.h && box1.d >= box2.d) {
  6. if (box1.w === box2.w && box1.h === box2.h && box1.d === box2.d)
  7. return 'Boxes are equal';
  8. return 'The first box is larger than the second one';
  9. }
  10.  
  11. if (box2.w >= box1.w && box2.h >= box1.h && box2.d >= box1.d)
  12. return 'The first box is smaller than the second one';
  13. return null;
  14. }
  15.  
  16. const result = check(box1, box2)
  17. || check({w: box1.h, h: box1.w, d: box1.d}, box2)
  18. || check({w: box1.w, h: box1.d, d: box1.h}, box2)
  19. || check({w: box1.d, h: box1.h, d: box1.w}, box2);
  20.  
  21. return result ? result : 'Boxes are incomparable';
  22. }
  23.  
  24. console.log(checkBox({w: 1, h: 2, d: 3}, {w: 3, h: 2, d: 1}));
  25. console.log(checkBox({w: 2, h: 2, d: 3}, {w: 3, h: 2, d: 1}));
  26. console.log(checkBox({w: 2, h: 2, d: 3}, {w: 3, h: 2, d: 3}));
  27. console.log(checkBox({w: 3, h: 4, d: 5}, {w: 2, h: 4, d: 6}));
Add Comment
Please, Sign In to add comment