Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaVoucher(input) {
- let voucher = Number(input.shift());
- let ticket = 0;
- let other = 0;
- while (true) {
- let buy = input.shift();
- if (buy === "End") {
- break;
- }
- let price = 0;
- if (buy.length > 8) {
- for (let i = 0; i < 2; i++) {
- price += buy.charCodeAt(i);
- }
- if (voucher >= price) {
- voucher -= price;
- ticket++;
- } else {
- break;
- }
- } else {
- price = buy.charCodeAt(0);
- if (voucher >= price) {
- voucher -= price;
- other++;
- } else {
- break;
- }
- }
- }
- console.log(ticket);
- console.log(other);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement