This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy path5-journey-planner.js
More file actions
52 lines (41 loc) · 1.51 KB
/
5-journey-planner.js
File metadata and controls
52 lines (41 loc) · 1.51 KB
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
/*
I am new to London and would like to know what transport I can take to different famous locations.
An array with London locations, and the forms of transport you can take to get there, have been provided.
Return an array of where I can go if I only want to use a specific mode of transport.
NOTE: only the names should be returned, not the means of transport.
*/
function journeyPlanner(locations, travelType) {
return locations.filter(location => location.includes(travelType)).map(location => location[0])
}
/* ======= TESTS - DO NOT MODIFY ===== */
const londonLocations = [
["Angel", "tube", "bus"],
["Greenwich", "bus", "river boat", "dlr", "air line", "tube"],
["London Bridge", "tube", "river boat"],
["Tower Bridge", "tube", "bus"],
]
const util = require('util');
function test(test_name, actual, expected) {
let status;
if (util.isDeepStrictEqual(actual, expected)) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}
console.log(`${test_name}: ${status}`);
}
test(
"journeyPlanner function works - case 1",
journeyPlanner(londonLocations, "river boat"),
["Greenwich", "London Bridge"]
);
test(
"journeyPlanner function works - case 2",
journeyPlanner(londonLocations, "bus"),
["Angel", "Greenwich", "Tower Bridge"]
);
test(
"journeyPlanner function works - case 3",
journeyPlanner(londonLocations, "tube"),
["Angel", "Greenwich", "London Bridge", "Tower Bridge"]
);