Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let movieName = input.shift();
- let ticketStudentCount = 0;
- let ticketStandardCount = 0;
- let ticketKidsCount = 0;
- let takenPlaces;
- let ticketsBought = 0;
- let isFinished = false;
- while(movieName != 'Finish') {
- // restart all vars
- takenPlaces = 0;
- let freePlaces = Number(input.shift());
- let ticketType = input.shift();
- // loop
- while(ticketType != 'End') {
- if(ticketType == 'Finish') {
- isFinished = true;
- break;
- }
- if(ticketType == 'standard') {
- ticketStandardCount++;
- } else if (ticketType == 'student') {
- ticketStudentCount++;
- } else {
- ticketKidsCount++;
- }
- takenPlaces++;
- ticketsBought++;
- ticketType = input.shift();
- }
- // result
- let percentTakenPlaces = (takenPlaces / freePlaces) * 100;
- console.log(`${movieName} - ${percentTakenPlaces.toFixed(2)}% full.`);
- movieName = input.shift();
- if(isFinished) {
- break;
- }
- }
- let percentKids = (ticketKidsCount / ticketsBought) * 100;
- let percentStandard = (ticketStandardCount / ticketsBought) * 100;
- let percentStudent = (ticketStudentCount / ticketsBought) * 100;
- console.log(`Total tickets: ${ticketsBought}`);
- console.log(`${percentStudent.toFixed(2)}% student tickets.`);
- console.log(`${percentStandard.toFixed(2)}% standard tickets.`);
- console.log(`${percentKids.toFixed(2)}% kids tickets.`);
- }
Add Comment
Please, Sign In to add comment