Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.    
  3.     let destination = input.shift();
  4.     let neededMoney = +input.shift();
  5.     let incommingMoney = 0;
  6.     let sum = 0;
  7.  
  8.     while(destination !== 'End'){
  9.         sum = 0;
  10.         while(neededMoney > sum){
  11.             incommingMoney = input.shift();
  12.             sum += Number(incommingMoney);
  13.             if(neededMoney <= sum) {
  14.                 console.log(`Going to ${destination}!`);
  15.                 break;
  16.             }
  17.         }
  18.  
  19.         destination = input.shift()
  20.         neededMoney = +input.shift()
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement