Advertisement
dimoBs

Untitled

Oct 24th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. function solve(input) {
  2. let index = 0;
  3. let aim = Number(input[index++]);
  4. let command = input[index];
  5. let priceDrinks = 0;
  6.  
  7. while (command !== "Party!") {
  8. if (aim <= priceDrinks) {
  9. break;
  10. }
  11. let nameOfdrink = command;
  12. let price = command.length;
  13. index++;
  14. command = Number(input[index]);
  15. priceDrinks += command * price;
  16.  
  17. if (priceDrinks % 2 == 1) {
  18. priceDrinks = priceDrinks * (1 - 0.25);
  19. }
  20. if (aim <= priceDrinks) {
  21. break;
  22. }
  23. index++;
  24. command = input[index];
  25. }
  26. console.log(priceDrinks);
  27. console.log(aim - priceDrinks);
  28. }
  29. //solve([500, "Bellini", 6, "Bamboo", 7, "Party!"]);
  30. solve([100,
  31. "Sidecar",
  32. 7,
  33. "Mojito",
  34. 5,
  35. "White Russian",
  36. 10
  37. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement