Ivankooo1

Bus

Jul 4th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. function Bus(input){
  2. let Passagers = Number(input.shift());
  3. let stops = Number(input.shift());
  4.  
  5. for(let i = 1; i <= stops; i++ ){
  6. let exitPeople = Number(input.shift());
  7. let enterPeople = Number(input.shift());
  8.  
  9. Passagers -= exitPeople;
  10. Passagers += enterPeople;
  11.  
  12. if(i % 2 === 0){
  13. Passagers -= 2;
  14.  
  15.  
  16. }else{
  17. Passagers += 2;
  18. }
  19. }
  20. console.log(`The final number of passengers is : ${Passagers}`);
  21. }
  22. Bus([20,2,10,5,5,3]);
Advertisement
Add Comment
Please, Sign In to add comment