Advertisement
RRusev77

05.Travelling

Apr 25th, 2020
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(...input) {
  2.     let destinationName = input.shift();
  3.    
  4.     let sum;
  5.  
  6.     while(destinationName != 'End') {
  7.         let neededMoney = input.shift();
  8.         sum = 0;
  9.  
  10.         while(true) {
  11.             let income = input.shift();
  12.             sum += income;
  13.            
  14.             if(sum >= neededMoney) {
  15.                 console.log(`Going to ${destinationName}!`);
  16.                 break;
  17.             }
  18.         }
  19.         destinationName = input.shift();
  20.     }
  21.  
  22. }
  23.  
  24. solve('Greece', 1000, 200, 200, 300, 100, 150, 240, 'Spain', 1200, 300, 500, 193, 423, 'End');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement