Advertisement
Neri0817

Traveling

Apr 16th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function traveling(input) {
  2.     let destination = input[0];
  3.     let moneyForGoing = Number(input[1]);
  4.     let index = 1;
  5.     let budget = 0;
  6.  
  7.     while (destination !== "End") {
  8.         index++;
  9.         while (budget < moneyForGoing) {
  10.             budget += Number(input[index]);
  11.             index++;
  12.         }
  13.         console.log(`Going to ${destination}!`);
  14.         destination = input[index++];
  15.         moneyForGoing = Number(input[index]);
  16.         budget = 0;
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement