Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const checkBox = (box1, box2) => {
- const check = (box1, box2) => {
- if (box1.w >= box2.w && box1.h >= box2.h && box1.d >= box2.d) {
- if (box1.w === box2.w && box1.h === box2.h && box1.d === box2.d)
- return 'Boxes are equal';
- return 'The first box is larger than the second one';
- }
- if (box2.w >= box1.w && box2.h >= box1.h && box2.d >= box1.d)
- return 'The first box is smaller than the second one';
- return null;
- }
- const result = check(box1, box2)
- || check({w: box1.h, h: box1.w, d: box1.d}, box2)
- || check({w: box1.w, h: box1.d, d: box1.h}, box2)
- || check({w: box1.d, h: box1.h, d: box1.w}, box2);
- return result ? result : 'Boxes are incomparable';
- }
- console.log(checkBox({w: 1, h: 2, d: 3}, {w: 3, h: 2, d: 1}));
- console.log(checkBox({w: 2, h: 2, d: 3}, {w: 3, h: 2, d: 1}));
- console.log(checkBox({w: 2, h: 2, d: 3}, {w: 3, h: 2, d: 3}));
- console.log(checkBox({w: 3, h: 4, d: 5}, {w: 2, h: 4, d: 6}));
Add Comment
Please, Sign In to add comment