Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaTickets(input) {
- let tickets = {'kid': 0, 'student': 0, 'standard': 0};
- while (input[0] !== 'Finish') {
- let movie = input.shift();
- let freeSeats = Number(input.shift());
- let sellTicket = 0;
- while (input[0] !== 'End' && freeSeats !== sellTicket) {
- tickets[input.shift()]++;
- sellTicket++;
- }
- console.log(`${movie} - ${((sellTicket / freeSeats) * 100).toFixed(2)}% full.`);
- movie = input[0] === 'End' ? input.shift() : '';
- }
- let totalTickets = Object.values(tickets).reduce((a, b) => a + b, 0);
- console.log(`Total tickets: ${totalTickets}`);
- console.log(`${(tickets['student'] / totalTickets * 100).toFixed(2)}% student tickets.`);
- console.log(`${(tickets['standard'] / totalTickets * 100).toFixed(2)}% standard tickets.`);
- console.log(`${(tickets['kid'] / totalTickets * 100).toFixed(2)}% kids tickets.`);
- }
Add Comment
Please, Sign In to add comment