Advertisement
vladovip

JS FUND MIDEX_PREP_The Lift

May 7th, 2022 (edited)
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lift(inputArr) {
  2.   let peopleNum = +inputArr.shift();
  3.   let arrOfWagons = inputArr.shift().split(" ");
  4.   // console.log( peopleNum, arrOfWagons);
  5.  
  6.   for (let index = 0; index < arrOfWagons.length; index++) {
  7.     while (Number(arrOfWagons[index]) < 4 && peopleNum > 0) {
  8.       let currentNumPeopWagon = Number(arrOfWagons[index]);
  9.       currentNumPeopWagon++;
  10.       peopleNum--;
  11.       arrOfWagons[index] = currentNumPeopWagon;
  12.     }
  13.   }
  14.  
  15.   if (peopleNum <= 0 && arrOfWagons[arrOfWagons.length - 1] < 4 ) {
  16.    
  17.         console.log(`The lift has empty spots!`);
  18.         console.log(`${arrOfWagons.join(" ")}`);
  19.    
  20.   }
  21.  
  22.   if ( peopleNum > 0 && arrOfWagons[arrOfWagons.length - 1] == 4 ) {
  23.     console.log(`There isn't enough space! ${peopleNum} people in a queue!`);
  24.    console.log(`${arrOfWagons.join(" ")}`);
  25.  }
  26.  
  27.  
  28.  if( arrOfWagons[arrOfWagons.length - 1] == 4 && peopleNum <= 0   ){
  29.      console.log(`${arrOfWagons.join(" ")}`);
  30.  }
  31.  
  32. }
  33.  
  34. lift(["15", "0 0 0 0 0"]);
  35.  
  36. console.log(`-----------`);
  37.  
  38. lift(["20", "0 2 0"]);
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement