Advertisement
Spocoman

05. Traveling

Dec 30th, 2021 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function traveling(input) {
  2.     let destination = "";
  3.     index = 0;
  4.  
  5.     while (true) {
  6.         destination = input[index++];
  7.         if (destination === "End") {
  8.             break;
  9.         }
  10.         let budget = Number(input[index++]);
  11.         while (budget > 0) {
  12.             budget -= Number(input[index++]);
  13.         }
  14.         console.log(`Going to ${destination}!`);
  15.     }
  16. }
  17.  
  18. ИЛИ:
  19.  
  20. function traveling(input) {
  21.     let destination = "";
  22.     index = 0;
  23.  
  24.     while ((destination = input[index++]) !== "End") {
  25.         let budget = Number(input[index++]);
  26.         while (budget > 0) {
  27.             budget -= Number(input[index++]);
  28.         }
  29.         console.log(`Going to ${destination}!`);
  30.     }
  31. }
  32.  
  33. РЕШЕНИЕ СЪС SHIFT():
  34.  
  35. function traveling(input) {
  36.     let destination = "";
  37.  
  38.     while ((destination = input.shift()) !== "End") {
  39.         let budget = Number(input.shift());
  40.         while (budget > 0) {
  41.             budget -= Number(input.shift());
  42.         }
  43.         console.log(`Going to ${destination}!`);
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement