Advertisement
ErolKZ

Untitled

Jul 13th, 2021
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5. let city = input[0];
  6.  
  7. let budged = Number(input[1]);
  8.  
  9.  
  10. let gatheredSum = 0;
  11.  
  12. let index = 2;
  13.  
  14.  
  15.  
  16. while (input[index] !== 'End') {
  17.  
  18.  
  19. while (!isNaN(Number(input[index]))) {
  20.  
  21. gatheredSum += Number(input[index]);
  22.  
  23. index++;
  24.  
  25. if (gatheredSum >= budged) {
  26.  
  27. console.log(`Going to ${city}!`);
  28.  
  29. break;
  30.  
  31. }
  32.  
  33. }
  34.  
  35.  
  36. city = input[index];
  37.  
  38. budged = Number(input[index + 1]);
  39.  
  40. gatheredSum = 0;
  41.  
  42. if (input[index] !== 'End') {
  43.  
  44. index = index + 2;
  45.  
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement