Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function theLift(input) {
- let people = Number(input[0]);
- let wagons = input[1].split(' ').map(Number);
- for (let i = 0; i < wagons.length; i++) {
- for (let j = wagons[i]; j < 4; j++) {
- if (people == 0) {
- break;
- }
- wagons[i]++;
- people--;
- }
- }
- if (wagons[wagons.length - 1] < 4) {
- console.log("The lift has empty spots!");
- } else if (people > 0) {
- console.log(`There isn't enough space! ${people} people in a queue!`);
- }
- console.log(wagons.join(' '));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement