Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bus(input) {
- let passengers = Number(input[0]);
- let stations = Number(input[1]);
- let index = 2;
- for (let i = 1; i <= stations; i++) {
- let outputPassengers = Number(input[index++]);
- let inputPassengers = Number(input[index++]);
- passengers += inputPassengers - outputPassengers;
- if (i % 2 == 1) {
- passengers += 2;
- } else {
- passengers -= 2;
- }
- }
- console.log(`The final number of passengers is : ${passengers}`);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement