Advertisement
Btwonu

Suitcase Load

Apr 28th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. function suitcasesLoad(input) {
  4.   //Input
  5.   let luggageCapacity = Number(input.shift());
  6.   let command = input.shift();
  7.   let noMoreSpace = false;
  8.   let luggageStored = 0;
  9.  
  10.   let loopCounter = 0;
  11.   while (command != 'End') {
  12.     let caseVolume = Number(command);
  13.     loopCounter++;
  14.  
  15.     if (loopCounter == 3) {
  16.       caseVolume *= 1.1;
  17.       loopCounter = 0;
  18.     }
  19.  
  20.     if (luggageCapacity < caseVolume) {
  21.       noMoreSpace = true;
  22.       break;
  23.     }
  24.     luggageCapacity -= caseVolume;
  25.     luggageStored++;
  26.  
  27.     command = input.shift();
  28.   }
  29.   //Output
  30.   if (!noMoreSpace) {
  31.     console.log(`Congratulations! All suitcases are loaded!`);
  32.   } else {
  33.     console.log(`No more space!`);
  34.   }
  35.   console.log(`Statistic: ${luggageStored} suitcases loaded.`);
  36. }
  37.  
  38. suitcasesLoad(
  39.   [ '550', '100', '252', '72', 'End', '' ]
  40. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement