-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumberOfPeopleInTheBus.js
40 lines (39 loc) · 1.25 KB
/
NumberOfPeopleInTheBus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Description:
*
* There is a bus moving in the city which takes and drops
* some people at each bus stop.
*
* You are provided with a list
* (or array) of integer pairs. Elements of each pair
* represent the number of people that get on the bus
* (the first item) and the number of people that get
* off the bus (the second item) at a bus stop.
*
* Your task is to return the number of people who are
* still on the bus after the last bus stop (after the last array).
* Even though it is the last bus stop, the bus might not be
* empty and some people might still be inside the bus, they
* are probably sleeping there :D
*
* Take a look on the test cases.
*
* Please keep in mind that the test cases
* ensure that the number of people in the bus
* is always >= 0. So the returned integer can't be negative.
*
* The second value in the first pair in the array is 0,
* since the bus is empty in the first bus stop.
*
* Kata URL: https://www.codewars.com/kata/5648b12ce68d9daa6b000099
*
* @param {*} busStops
* @returns Number of people still inside the bus after the last bus stop
*/
var number = function (busStops) {
let count = 0;
busStops.forEach((element) => {
count = count + element[0] - element[1];
});
return count;
};