Advertisement
Spocoman

Bus

Oct 9th, 2023
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bus(input) {
  2.     let passengers = Number(input[0]);
  3.     let stations = Number(input[1]);
  4.     let index = 2;
  5.  
  6.     for (let i = 1; i <= stations; i++) {
  7.         let outputPassengers = Number(input[index++]);
  8.         let inputPassengers = Number(input[index++]);
  9.  
  10.         passengers += inputPassengers - outputPassengers;
  11.  
  12.         if (i % 2 == 1) {
  13.             passengers += 2;
  14.         } else {
  15.             passengers -= 2;
  16.         }
  17.     }
  18.  
  19.     console.log(`The final number of passengers is : ${passengers}`);
  20.     return;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement