Advertisement
Spocoman

06. Cinema Tickets

Dec 31st, 2021 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. РЕШЕНИЕ С РЕЧНИК И SHIFT() ЛЕКО ТАРИКАТСКАТА:
  2.  
  3. function cinemaTickets(input) {
  4.     let tickets = {kid: 0, student: 0, standard: 0};
  5.  
  6.     while (input[0] !== 'Finish') {
  7.         let movie = input.shift();
  8.         let volume = Number(input.shift());
  9.         let soldTicket = 0;
  10.         while (input[0] !== 'End' && soldTicket !== volume) {
  11.             tickets[input.shift()]++;
  12.             soldTicket++;
  13.         }
  14.         console.log(`${movie} - ${((soldTicket / volume) * 100).toFixed(2)}% full.`);
  15.         if (soldTicket !== volume) {
  16.             input.shift();
  17.         }
  18.     }
  19.  
  20.     let totalTicket = tickets.kid + tickets.student + tickets.standard;
  21.     console.log(`Total tickets: ${totalTicket}`);
  22.     console.log(`${((tickets.student / totalTicket) * 100).toFixed(2)}% student tickets.`);
  23.     console.log(`${((tickets.standard / totalTicket) * 100).toFixed(2)}% standard tickets.`);
  24.     console.log(`${((tickets.kid / totalTicket) * 100).toFixed(2)}% kids tickets.`);
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement