Advertisement
ErolKZ

Untitled

Jul 7th, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5. let nameMovie = input[0];
  6.  
  7. let freeSeats = Number(input[1]);
  8.  
  9. let student = 0;
  10.  
  11. let standard = 0;
  12.  
  13. let kids = 0;
  14.  
  15. let index = 2;
  16.  
  17. let percentOfSeats = 0;
  18.  
  19. let totalTickets = 0;
  20.  
  21. let percentStudent = 0;
  22.  
  23. let percentStandard = 0;
  24.  
  25. let percentKids = 0;
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. while (input[index] !== undefined) {
  33.  
  34.  
  35. let current = input[index];
  36.  
  37.  
  38. switch (current) {
  39.  
  40. case 'student':
  41.  
  42. student += 1;
  43.  
  44. break;
  45.  
  46.  
  47. case 'standard':
  48.  
  49. standard += 1;
  50.  
  51. break;
  52.  
  53.  
  54. case 'kid':
  55.  
  56. kids += 1;
  57.  
  58. break;
  59.  
  60. }
  61.  
  62.  
  63. if (input[index] !== 'End') {
  64.  
  65. index++;
  66.  
  67. }
  68.  
  69.  
  70. if (input[index] === 'End' || input[index] === 'Finish') {
  71.  
  72.  
  73. percentOfSeats = ((student + standard + kids) / freeSeats) * 100;
  74.  
  75. console.log(`${nameMovie} - ${percentOfSeats.toFixed(2)}% full.`);
  76.  
  77. totalTickets += student + standard + kids;
  78.  
  79. percentStudent += student;
  80.  
  81. percentStandard += standard;
  82.  
  83. percentKids += kids;
  84.  
  85. percentOfSeats = 0;
  86.  
  87. student = 0;
  88.  
  89. standard = 0;
  90.  
  91. kids = 0;
  92.  
  93.  
  94. nameMovie = input[index + 1];
  95.  
  96. freeSeats = Number(input[index + 2])
  97.  
  98.  
  99.  
  100.  
  101. if (input[index] !== 'Finish') {
  102.  
  103. index = index + 3;
  104.  
  105. }
  106.  
  107. }
  108. if (input[index] === 'Finish') {
  109.  
  110. percentStudent = (percentStudent / totalTickets) * 100;
  111.  
  112. percentStandard = (percentStandard / totalTickets) * 100;
  113.  
  114. percentKids = (percentKids / totalTickets) * 100;
  115.  
  116. console.log(`Total tickets: ${totalTickets}`);
  117. console.log(`${percentStudent.toFixed(2)}% student tickets.`);
  118. console.log(`${percentStandard.toFixed(2)}% standard tickets.`);
  119. console.log(`${percentKids.toFixed(2)}% kids tickets.`);
  120.  
  121. break;
  122.  
  123.  
  124. }
  125.  
  126.  
  127. } // while loop
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement