Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function suitcaseLoad(input) {
- let size = Number(input[0]);
- let counter = 1;
- while (true) {
- let suitcase = input[counter];
- if (suitcase == "End") {
- console.log("Congratulations! All suitcases are loaded!");
- break;
- }
- let box = Number(suitcase);
- if (counter % 3 == 0) {
- box *= 1.1;
- }
- if (box > size) {
- console.log("No more space!");
- break;
- }
- size -= box;
- counter++;
- }
- console.log(`Statistic: ${--counter} suitcases loaded.`);
- }
- РЕШЕНИЕ С FOR И ТЕРНАРЕН ОПЕРАТОР ЛЕКО ТАРИКАТСКАТА:
- function suitcaseLoad(input) {
- let size = Number(input[0]);
- for (let i = 1; i < input.length; i++) {
- if (input[i] == "End") {
- console.log(`Congratulations! All suitcases are loaded!\nStatistic: ${--i} suitcases loaded.`);
- break;
- }
- let box = Number(input[i]) * (i % 3 == 0 ? 1.1 : 1);
- if (box > size) {
- console.log(`No more space!\nStatistic: ${--i} suitcases loaded.`);
- break;
- }
- size -= box;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement