Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function baggage(input) {
- let index = 0;
- let freeSpace = Number(input[index]);
- index++;
- let command = input[index];
- index++;
- let luggage = 0;
- let counter = 0;
- let enoughtSpaceLeft = true;
- while (command !== "End") {
- let suitCaseSpace = Number(command);
- luggage++;
- if (luggage % 3 === 0 && counter !== 0) {
- suitCaseSpace = suitCaseSpace + (suitCaseSpace * 0.10);
- }
- if (suitCaseSpace > freeSpace) {
- enoughtSpaceLeft = false;
- console.log("No more space!");
- console.log(`Statistic: ${counter} suitcases loaded.`);
- break;
- }
- counter++;
- freeSpace -= suitCaseSpace;
- command = input[index];
- index++;
- }
- if (enoughtSpaceLeft) {
- console.log("Congratulations! All suitcases are loaded!");
- console.log(`Statistic: ${counter} suitcases loaded.`);
- }
- }
- baggage(["550", "100", "252", "72", "End"]);
- baggage(["700.5", "180", "340.6", "126", "220"]);
- baggage(["1200.2", "260", "380.5", "125.6", "305", "End"]);
Add Comment
Please, Sign In to add comment