Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaVoucher(input) {
- let index = 0;
- let voucherPrice = Number(input[index]);
- index++;
- let command = input[index];
- index++;
- let ticketCounter = 0;
- let purchaseCounter = 0;
- while (command !== "End") {
- if (command.length > 8) {
- let ticketPrice = command.charCodeAt(0) + command.charCodeAt(1);
- if ((voucherPrice - ticketPrice) < 0) {
- break;
- } else {
- ticketCounter++;
- voucherPrice -= ticketPrice;
- }
- } else if (command.length <= 8) {
- let purchasePrice = command.charCodeAt(0);
- if ((voucherPrice - purchasePrice) < 0) {
- break;
- } else {
- purchaseCounter++;
- voucherPrice -= purchasePrice;
- }
- }
- command = input[index];
- index++;
- }
- console.log(ticketCounter);
- console.log(purchaseCounter);
- }
- cinemaVoucher(["300", "Captain Marvel", "popcorn", "Pepsi"]);
- cinemaVoucher(["1500", "Avengers: End Game", "Bohemian Rhapsody", "Deadpool 2", "End"]);
Advertisement
Add Comment
Please, Sign In to add comment