Advertisement
dimoBs

Untitled

Oct 17th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. function jorney(input) {
  2. let index = 0;
  3. let destination = "";
  4. // index++;
  5. let bugetMin = "";
  6. // index++;
  7. let bugetNeed = 0;
  8. let command = input[index];
  9.  
  10. while (command !== "End") {
  11. destination = input[index];
  12. index++;
  13. bugetMin = Number(input[index]);
  14. index++;
  15. bugetNeed = 0;
  16.  
  17. while (bugetNeed <= bugetMin) {
  18. command = input[index];
  19. let commandNext = Number(command);
  20. bugetNeed += commandNext;
  21. index++;
  22. if (bugetNeed >= bugetMin) {
  23. console.log(`Going to ${destination}!`);
  24. // destination = input[index];
  25. command = input[index];
  26. break;
  27. }
  28. }
  29. }
  30. }
  31. // jorney([
  32. // "Greece",
  33. // "1000",
  34. // "200",
  35. // "200",
  36. // "300",
  37. // "100",
  38. // "150",
  39. // "240",
  40. // "Spain",
  41. // "1200",
  42. // "300",
  43. // "500",
  44. // "193",
  45. // "423",
  46. // "End",
  47. // ]);
  48. jorney(["France",
  49. "2000",
  50. "300",
  51. "300",
  52. "200",
  53. "400",
  54. "190",
  55. "258",
  56. "360",
  57. "Portugal",
  58. "1450",
  59. "400",
  60. "400",
  61. "200",
  62. "300",
  63. "300",
  64. "Egypt",
  65. "1900",
  66. "1000",
  67. "280",
  68. "300",
  69. "500",
  70. "End"
  71. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement