Advertisement
PowerCell46

JOURNEY JS

Oct 17th, 2022
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function journey(input) {
  2.     let index = 0;
  3.     let destination = input[index];
  4.     index++;
  5.     let minimumBudget = Number(input[index]);
  6.     index++;
  7.     let currentSum = Number(input[index]);
  8.     let collectedMoney = 0;
  9.  
  10.     while(destination !== "End") {
  11.  
  12.         while(collectedMoney < minimumBudget) {
  13.             collectedMoney += currentSum;
  14.             if(collectedMoney >= minimumBudget) {
  15.             continue;
  16.             }
  17.             index++;
  18.             currentSum = Number(input[index]);
  19.         }
  20.         console.log("Going to " + destination + "!");
  21.         collectedMoney = 0;
  22.         index++;
  23.         destination = input[index];
  24.         if(destination === "End") {
  25.             continue;
  26.         }
  27.         index++;
  28.         minimumBudget = Number(input[index]);
  29.         index++;
  30.         currentSum = Number(input[index]);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement