Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ С FOR:
- function excursionSale(input) {
- let seaCount = Number(input[0]);
- let mountCount = Number(input[1]);
- let totalSum = 0;
- for (let i = 2; i < input.length; i++) {
- let command = input[i];
- if (command === "Stop") {
- break;
- } else if (command === "sea") {
- if (seaCount !== 0) {
- totalSum += 680;
- seaCount--;
- }
- } else if (command === "mountain") {
- if (mountCount !== 0) {
- totalSum += 499;
- mountCount--;
- }
- }
- if (seaCount === 0 && mountCount === 0) {
- console.log(" Good job! Everything is sold.");
- break;
- }
- }
- console.log(`Profit: ${totalSum} leva.`);
- }
- РЕШЕНИЕ СЪС SHIFT():
- function excursionSale(input) {
- let seaCount = Number(input.shift());
- let mountCount = Number(input.shift());
- let totalSum = 0;
- while (true) {
- let command = input.shift();
- if (command === "Stop") {
- break;
- } else if (command === "sea") {
- if (seaCount !== 0) {
- totalSum += 680;
- seaCount--;
- }
- } else if (command === "mountain") {
- if (mountCount !== 0) {
- totalSum += 499;
- mountCount--;
- }
- }
- if (seaCount === 0 && mountCount === 0) {
- console.log(" Good job! Everything is sold.");
- break;
- }
- }
- console.log(`Profit: ${totalSum} leva.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement