Advertisement
Btwonu

Travelling

Apr 25th, 2020
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function travelling(input) {
  2.   //Input
  3.  
  4.  
  5.   let command = input.shift();
  6.   let savings = 0;
  7.  
  8.   while (command != 'End') {
  9.     let destination = command;
  10.     let budgetNeeded = Number(input.shift());
  11.    
  12.     while (savings < budgetNeeded) {
  13.       savings += Number(input.shift());
  14.     }
  15.     console.log(`Going to ${destination}!`);
  16.    
  17.     command = input.shift();
  18.     savings = 0;
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement