Advertisement
ErolKZ

Untitled

Jun 17th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5. let vaucherValue = Number(input[0]);
  6.  
  7. let prize = 0;
  8.  
  9. let tickets = 0;
  10.  
  11. let others = 0;
  12.  
  13.  
  14.  
  15. for (let i = 1; i < input.length; i++) {
  16.  
  17.  
  18. if (input[i] !== 'End') {
  19.  
  20. if (input[i].length > 8) {
  21.  
  22. prize = input[i].charCodeAt(0) + input[i].charCodeAt(1);
  23.  
  24. if (prize < vaucherValue) {
  25.  
  26. vaucherValue = vaucherValue - prize;
  27. tickets += 1;
  28. }
  29.  
  30.  
  31. } else if (input[i].length <= 8) {
  32.  
  33. prize = input[i].charCodeAt(0);
  34.  
  35. if (prize < vaucherValue) {
  36.  
  37. vaucherValue = vaucherValue - prize;
  38. others += 1;
  39.  
  40. }
  41.  
  42.  
  43.  
  44. }
  45.  
  46. } else {
  47.  
  48. break;
  49.  
  50. }
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. console.log(tickets);
  60. console.log(others);
  61.  
  62.  
  63.  
  64. }
  65.  
  66.  
  67. solve([
  68.  
  69. '1500',
  70. 'Avengers: Endgame',
  71. 'Bohemian Rhapsody',
  72. 'Deadpool 2',
  73. 'Pepsi',
  74. 'End'
  75.  
  76.  
  77.  
  78. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement