-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday11.js
62 lines (51 loc) · 1.47 KB
/
day11.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ./day11.js
/*
Challenge #11 - You Can't Hurry Transit
You can't hurry love, or local transit in Codeville. While you've been hard at work on a solution to the
larger transit woes, you've decided to implement a new system to at least be a little more transparent
about wait times. The city will be installing a smart screen, at the busiest bus stop in town, that will
show the estimated arrival times for each of the buses that stop there.
Instructions
For this challenge, we'll implement a function called busTimes(). This function will calculate the arrival
time for a collection of busses based on their current speed and distance from the stop. It will receive an
object called buses, which contains a series of objects for each bus, with the distance of the bus and the
speed that the bus is traveling at. Our function should return a new object that shows how long until each
bus arrives at the stop.
Examples:
INPUT:
const buses = {
pickadilly: {
distance: 10,
speed: 5
},
uptown: {
distance: 13,
speed: 10
}
}
OUTPUT:
{
pickadilly: 2,
uptown: 1.3
}
*/
const busTimes = (buses) => {
const busRoutes = Object.keys(buses);
const arrivalTimes = {}
busRoutes.forEach(route => {
arrivalTimes[route] = buses[route].distance / buses[route].speed;
});
return arrivalTimes;
};
// EXAMPLE:
const buses = {
pickadilly: {
distance: 10,
speed: 5
},
uptown: {
distance: 13,
speed: 10
}
};
console.log(busTimes(buses));