Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let index = 0;
- let aim = Number(input[index++]);
- let command = input[index];
- let priceDrinks = 0;
- while (command !== "Party!") {
- if (aim <= priceDrinks) {
- break;
- }
- let nameOfdrink = command;
- let price = command.length;
- index++;
- command = Number(input[index]);
- priceDrinks += command * price;
- if (priceDrinks % 2 == 1) {
- priceDrinks = priceDrinks * (1 - 0.25);
- }
- if (aim <= priceDrinks) {
- break;
- }
- index++;
- command = input[index];
- }
- console.log(priceDrinks);
- console.log(aim - priceDrinks);
- }
- //solve([500, "Bellini", 6, "Bamboo", 7, "Party!"]);
- solve([100,
- "Sidecar",
- 7,
- "Mojito",
- 5,
- "White Russian",
- 10
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement