ErolKZ

Untitled

Jun 21st, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5. let hrExam = Number(input[0]);
  6.  
  7. let minExam = Number(input[1]);
  8.  
  9. let hrArrival = Number(input[2]);
  10.  
  11. let minArrival = Number(input[3]);
  12.  
  13.  
  14. let hourDifference = hrExam - hrArrival;
  15.  
  16. let minDifference = minExam - minArrival;
  17.  
  18.  
  19. hourDifference = Math.abs(hourDifference);
  20.  
  21. minDifference = Math.abs(minDifference);
  22.  
  23. let difference = 60 - minDifference;
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. // ON TIME
  31.  
  32. if ((hrExam >= hrArrival && difference <= 30 || hourDifference === minDifference) && (difference <= 30 || difference === 60) || (minArrival < minExam && minDifference <= 30 && hourDifference === 0)) {
  33.  
  34.  
  35.  
  36. if (minDifference > 0 && difference <= 30) {
  37.  
  38. console.log(`On time`);
  39. console.log(`${difference} minutes before the start`);
  40.  
  41. } else if (hourDifference === 0 && minDifference === 0) {
  42.  
  43. console.log(`On time`);
  44.  
  45. } else {
  46.  
  47. console.log(`On time`);
  48. console.log(`${minDifference} minutes before the start`);
  49.  
  50.  
  51. }
  52.  
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
  59. // LATE
  60.  
  61.  
  62. if ((hrExam <= hrArrival && hourDifference !== minDifference && minArrival > minExam) || (difference > 30 && difference !== 60 && hrExam <= hrArrival && minArrival > minExam) || (hrExam < hrArrival && minArrival < minExam) || hrArrival > hrExam) {
  63.  
  64.  
  65. if (hrExam === hrArrival) {
  66.  
  67. console.log(`Late`);
  68. console.log(`${minDifference} minutes after the start`);
  69.  
  70. } else if (hrExam < hrArrival && difference <= 30) {
  71.  
  72.  
  73. if (minDifference > 9) {
  74.  
  75. console.log(`Late`);
  76. console.log(`${hourDifference}:${minDifference} hours after the start`);
  77.  
  78. } else {
  79.  
  80. console.log(`Late`);
  81. console.log(`${hourDifference}:0${minDifference} hours after the start`);
  82.  
  83. }
  84.  
  85.  
  86. } else if (difference > 30 && hrExam < hrArrival && difference !== 60 && minArrival < minExam) {
  87.  
  88. console.log(`Late`);
  89. console.log(`${difference} minutes after the start`);
  90.  
  91. } else {
  92.  
  93. if (minDifference > 9) {
  94.  
  95. console.log(`Late`);
  96. console.log(`${hourDifference}:${minDifference} hours after the start`);
  97.  
  98. } else {
  99.  
  100. console.log(`Late`);
  101. console.log(`${hourDifference}:0${minDifference} hours after the start`);
  102.  
  103. }
  104.  
  105.  
  106. }
  107.  
  108.  
  109. }
  110.  
  111.  
  112.  
  113.  
  114. // EARLY
  115.  
  116.  
  117. if ((difference > 30 && hrExam >= hrArrival && minDifference > 30) || (minArrival < minExam && minDifference > 30) || (hrExam > hrArrival && minArrival > minExam) || (difference === 60 && hrExam >= hrArrival) || (hourDifference >= 1 && hrExam >= hrArrival)) {
  118.  
  119.  
  120. if (minDifference <= 30 && difference < 60 && hourDifference <= 1 && minArrival > minExam) {
  121.  
  122. console.log(`Early`);
  123.  
  124. console.log(`${difference} minutes before the start`);
  125.  
  126. } else if (minDifference <= 30 && difference < 60 && hourDifference <= 1 && minArrival < minExam) {
  127.  
  128. console.log(`Early`);
  129.  
  130. console.log(`${minDifference} minutes before the start`);
  131.  
  132.  
  133. } else {
  134.  
  135. if (minDifference < 10) {
  136.  
  137. console.log(`Early`);
  138.  
  139. console.log(`${hourDifference}:0${minDifference} hours before the start`);
  140.  
  141.  
  142. } else {
  143.  
  144. console.log(`Early`);
  145.  
  146. console.log(`${hourDifference}:${minDifference} hours before the start`);
  147.  
  148. }
  149.  
  150. }
  151.  
  152.  
  153. }
  154.  
  155.  
  156.  
  157.  
  158. }
  159.  
  160. solve([
  161.  
  162. '11',
  163. '30',
  164. '10',
  165. '59'
  166.  
  167. ]);
  168.  
Advertisement
Add Comment
Please, Sign In to add comment