Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input) {
- let destination = input.shift();
- let neededMoney = +input.shift();
- let incommingMoney = 0;
- let sum = 0;
- while(destination !== 'End'){
- sum = 0;
- while(neededMoney > sum){
- incommingMoney = input.shift();
- sum += Number(incommingMoney);
- if(neededMoney <= sum) {
- console.log(`Going to ${destination}!`);
- break;
- }
- }
- destination = input.shift()
- neededMoney = +input.shift()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement