Advertisement
ErolKZ

Untitled

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