Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function travel(input) {
- let index = 0
- let destination = input[index];
- index++
- let neededSum = Number (input[index]);
- index++;
- let moneyOrDestination = 0
- let sum = 0;
- while (moneyOrDestination !== "End") {
- moneyOrDestination = Number (moneyOrDestination);
- if (sum >= neededSum) {
- console.log(`Going to ${destination}!`);
- destination = input[index-1];
- neededSum = Number (input [index])
- index++
- sum = 0
- moneyOrDestination = 0
- }
- sum = sum + moneyOrDestination;
- moneyOrDestination = input [index];
- index++;
- }
- if (sum >= neededSum) {
- console.log(`Going to ${destination}!`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement