ProdanTenev

Moving

Mar 2nd, 2022
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.69 KB | None | 0 0
  1. function moving(input) {
  2.     let index = 0;
  3.     let width = Number(input[index]);
  4.     index++;
  5.     let length = Number(input[index]);
  6.     index++;
  7.     let height = Number(input[index]);
  8.     index++;
  9.     let freeSpace = width * length * height;
  10.     while (freeSpace > 0) {
  11.         let command = input[index];
  12.         index++;
  13.         if (command === "Done") {
  14.             console.log(`${freeSpace} Cubic meters left.`);
  15.             break;
  16.         }
  17.         let currentBox = Number(command);
  18.         freeSpace -= currentBox;
  19.     }
  20.     if (freeSpace <= 0) {
  21.         let diff = Math.abs(freeSpace);
  22.         console.log(`No more free space! You need ${diff} Cubic meters more.`);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment