Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function jorney(input) {
- let index = 0;
- let destination = "";
- // index++;
- let bugetMin = "";
- // index++;
- let bugetNeed = 0;
- let command = input[index];
- while (command !== "End") {
- destination = input[index];
- index++;
- bugetMin = Number(input[index]);
- index++;
- bugetNeed = 0;
- while (bugetNeed <= bugetMin) {
- command = input[index];
- let commandNext = Number(command);
- bugetNeed += commandNext;
- index++;
- if (bugetNeed >= bugetMin) {
- console.log(`Going to ${destination}!`);
- // destination = input[index];
- command = input[index];
- break;
- }
- }
- }
- }
- // jorney([
- // "Greece",
- // "1000",
- // "200",
- // "200",
- // "300",
- // "100",
- // "150",
- // "240",
- // "Spain",
- // "1200",
- // "300",
- // "500",
- // "193",
- // "423",
- // "End",
- // ]);
- jorney(["France",
- "2000",
- "300",
- "300",
- "200",
- "400",
- "190",
- "258",
- "360",
- "Portugal",
- "1450",
- "400",
- "400",
- "200",
- "300",
- "300",
- "Egypt",
- "1900",
- "1000",
- "280",
- "300",
- "500",
- "End"
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement