Spocoman

Cinema Tickets

Jan 4th, 2022 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinemaTickets(input) {
  2.  
  3.     let tickets = {'kid': 0, 'student': 0, 'standard': 0};
  4.  
  5.     while (input[0] !== 'Finish') {
  6.         let movie = input.shift();
  7.         let freeSeats = Number(input.shift());
  8.         let sellTicket = 0;
  9.  
  10.         while (input[0] !== 'End' && freeSeats !== sellTicket) {
  11.             tickets[input.shift()]++;
  12.             sellTicket++;
  13.         }
  14.         console.log(`${movie} - ${((sellTicket / freeSeats) * 100).toFixed(2)}% full.`);
  15.         movie = input[0] === 'End' ? input.shift() : '';
  16.     }
  17.     let totalTickets = Object.values(tickets).reduce((a, b) => a + b, 0);
  18.     console.log(`Total tickets: ${totalTickets}`);
  19.     console.log(`${(tickets['student'] / totalTickets * 100).toFixed(2)}% student tickets.`);
  20.     console.log(`${(tickets['standard'] / totalTickets * 100).toFixed(2)}% standard tickets.`);
  21.     console.log(`${(tickets['kid'] / totalTickets * 100).toFixed(2)}% kids tickets.`);
  22. }
Add Comment
Please, Sign In to add comment