Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaVoucher(input) {
- let index = 0;
- let vaucherValue = Number(input[index]);
- index++;
- let command = input[index];
- let filmCounter = 0;
- let purchaseCounter = 0;
- while (command !== "End") {
- let purchase = command;
- let filmPrice = 0;
- let purchasePrice = 0;
- let firstChar = purchase[0];
- let secondChar = purchase[1];
- if (purchase.length > 8) {
- filmPrice =
- Number(firstChar.charCodeAt()) +
- Number(secondChar.charCodeAt());
- if (vaucherValue - filmPrice < 0) {
- break;
- }
- vaucherValue -= filmPrice;
- filmCounter++;
- } else {
- purchasePrice = Number(firstChar.charCodeAt());
- if (vaucherValue - purchasePrice < 0) {
- break;
- }
- vaucherValue -= purchasePrice;
- purchaseCounter++;
- }
- index++;
- command = input[index];
- }
- console.log(filmCounter);
- console.log(purchaseCounter);
- }
Advertisement
Add Comment
Please, Sign In to add comment