Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function traveling(input) {
- let destination = "";
- index = 0;
- while (true) {
- destination = input[index++];
- if (destination === "End") {
- break;
- }
- let budget = Number(input[index++]);
- while (budget > 0) {
- budget -= Number(input[index++]);
- }
- console.log(`Going to ${destination}!`);
- }
- }
- ИЛИ:
- function traveling(input) {
- let destination = "";
- index = 0;
- while ((destination = input[index++]) !== "End") {
- let budget = Number(input[index++]);
- while (budget > 0) {
- budget -= Number(input[index++]);
- }
- console.log(`Going to ${destination}!`);
- }
- }
- РЕШЕНИЕ СЪС SHIFT():
- function traveling(input) {
- let destination = "";
- while ((destination = input.shift()) !== "End") {
- let budget = Number(input.shift());
- while (budget > 0) {
- budget -= Number(input.shift());
- }
- console.log(`Going to ${destination}!`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement