Advertisement
Spocoman

02. The Lift

Nov 4th, 2023 (edited)
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function theLift(input) {
  2.     let people = Number(input[0]);
  3.     let wagons = input[1].split(' ').map(Number);
  4.  
  5.     for (let i = 0; i < wagons.length; i++) {
  6.         for (let j = wagons[i]; j < 4; j++) {
  7.             if (people == 0) {
  8.                 break;
  9.             }
  10.             wagons[i]++;
  11.             people--;
  12.         }
  13.     }
  14.  
  15.     if (wagons[wagons.length - 1] < 4) {
  16.         console.log("The lift has empty spots!");
  17.     } else if (people > 0) {
  18.         console.log(`There isn't enough space! ${people} people in a queue!`);
  19.    }
  20.  
  21.    console.log(wagons.join(' '));
  22.    return;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement