Didart

Traveling - Nested Loops

Apr 19th, 2022
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function traveling(input) {
  2.     let index = 0;
  3.     let command = input[index];
  4.     index++;
  5.  
  6.     while (command !== "End") {
  7.         let destination = command;
  8.         let budget = Number(input[index]);
  9.         index++;
  10.         let tempSum = 0;
  11.  
  12.         while (tempSum < budget) {
  13.             let money = Number(input[index]);
  14.             index++;
  15.             tempSum += money;
  16.         }
  17.         console.log(`Going to ${destination}!`);
  18.         command = input[index];
  19.         index++;
  20.     }
  21.  
  22. }
  23.  
  24. traveling(["Greece", "1000", "200", "200", "300", "100", "150", "240", "Spain", "1200", "300", "500", "193", "423", "End"])
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment