Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let city = input[0];
- let budged = Number(input[1]);
- let index = 0;
- let gatheredSum = 0;
- if (input[index] !== 'End') {
- index = 2;
- }
- while (input[index] !== 'End') {
- while (!isNaN(Number(input[index]))) {
- gatheredSum += Number(input[index]);
- index++;
- if (gatheredSum >= budged) {
- console.log(`Going to ${city}!`);
- break;
- }
- }
- city = input[index];
- budged = Number(input[index + 1]);
- gatheredSum = 0;
- if (input[index] !== 'End') {
- index = index + 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement