Advertisement
EntropyStarRover

5.bus

Feb 25th, 2019
150
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bus(input){
  2.     let startingPassengers=Number(input.shift());
  3.     let stops=Number(input.shift());
  4.    
  5.  
  6.     for (let i=1; i<=stops; i++){
  7.         if (i%2!=0){
  8.             startingPassengers+=2;
  9.         } else {
  10.             startingPassengers-=2;
  11.         }
  12.         let slizashti=Number(input.shift());
  13.         startingPassengers-=slizashti;
  14.         let kachvashtiSe=Number(input.shift());
  15.         startingPassengers+=kachvashtiSe;
  16.     }
  17.  
  18.     console.log(`The final number of passengers is : ${startingPassengers}`);
  19.  
  20. }
Advertisement
RAW Paste Data Copied
Advertisement