Guest User

Untitled

a guest
Nov 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. function parallelepipedSpace(a, b, c) {
  2. return 2 * (a * b + b * c + c * a);
  3. }
  4. function parallelepipedVolume(a, b, c) {
  5. return a * b * c;
  6. }
  7. function isEqual(a, b, c, a1, b1, c1) {
  8. return (parallelepipedSpace(a, b, c) === parallelepipedSpace(a1, b1, c1)) &&
  9. (parallelepipedVolume(a, b, c) === parallelepipedVolume(a1, b1, c1));
  10. }
  11. function isBiggerBox(a, b, c, a1, b1, c1) {
  12. var box1 = [a, b, c];
  13. var box2 = [a1, b1, c1];
  14.  
  15. for (var i = 0; i < box1.length; i++) {
  16.  
  17. if ((box1[0] >= box2[0]) && (box1[1] >= box2[1]) && (box1[2] >= box2[2])) {
  18. return true;
  19. }
  20. box1 = [box1[1], box1[2], box1[0]];
  21. }
  22. return false;
  23. }
  24.  
  25. //(1st box 1st side, 1st box 2st side, 1st box 3st side, 2st box 1st side, 2st box 2st side, 2st box 3st side)
  26. function comparison(a, b, c, a1, b1, c1) {
  27. if (isEqual(a, b, c, a1, b1, c1)) {
  28. return "Boxes are equal";
  29.  
  30. } else if (parallelepipedVolume(a, b, c) > parallelepipedVolume(a1, b1, c1) && isBiggerBox(a, b, c, a1, b1, c1)) {
  31.  
  32. return "The first box is larger than the second one";
  33. } else if (parallelepipedVolume(a, b, c) < parallelepipedVolume(a1, b1, c1) && isBiggerBox(a1, b1, c1, a, b, c)) {
  34.  
  35. return "The first box is smaller than the second one";
  36. }
  37.  
  38. return "Boxes are incomparable";
  39. }
  40.  
  41. console.log(comparison(1, 2, 3, 3, 2, 1));
  42. console.log(comparison(2, 2, 3, 3, 2, 1));
  43. console.log(comparison(2, 2, 3, 3, 2, 3));
  44. console.log(comparison(3, 4, 5, 2, 4, 6));
  45.  
  46. console.info(comparison(1, 1, 1, 2, 2, 2));
  47. console.info(comparison(1, 7, 1, 2, 2, 2));
  48. console.info(comparison(1, 2, 1, 2, 1, 2));
Add Comment
Please, Sign In to add comment