|
1 | 1 | /* |
2 | 2 | I am new to London and would like to know what transport I can take to different famous locations. |
3 | | - An array with London locations have been provided. |
| 3 | + An array with London locations, and the forms of transport you can take to get there, have been provided. |
4 | 4 |
|
5 | 5 | Return an array of where I can go if I only want to use a specific mode of transport. |
6 | 6 |
|
7 | 7 | NOTE: only the names should be returned, not the means of transport. |
8 | 8 | */ |
9 | 9 |
|
10 | 10 | function journeyPlanner() { |
11 | | - |
12 | 11 | } |
13 | 12 |
|
14 | 13 | /* ======= TESTS - DO NOT MODIFY ===== */ |
15 | 14 |
|
16 | 15 | const londonLocations = [ |
17 | 16 | ["Angel", "tube", "bus"], |
| 17 | + ["Greenwich", "bus", "river boat", "dlr", "air line", "tube"], |
18 | 18 | ["London Bridge", "tube", "river boat"], |
19 | 19 | ["Tower Bridge", "tube", "bus"], |
20 | | - ["Greenwich", "bus", "river boat"] |
21 | 20 | ] |
22 | 21 |
|
23 | | -function arraysEqual(a, b) { |
24 | | - if (a === b) return true; |
25 | | - if (a == null || b == null) return false; |
26 | | - if (a.length != b.length) return false; |
27 | | - |
28 | | - for (let i = 0; i < a.length; ++i) { |
29 | | - if (a[i] !== b[i]) return false; |
30 | | - } |
31 | | - |
32 | | - return true; |
33 | | -} |
| 22 | +const util = require('util'); |
34 | 23 |
|
35 | | -function test(test_name, expr) { |
| 24 | +function test(test_name, actual, expected) { |
36 | 25 | let status; |
37 | | - if (expr) { |
38 | | - status = "PASSED"; |
| 26 | + if (util.isDeepStrictEqual(actual, expected)) { |
| 27 | + status = "PASSED"; |
39 | 28 | } else { |
40 | | - status = "FAILED"; |
| 29 | + status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; |
41 | 30 | } |
42 | | - |
| 31 | + |
43 | 32 | console.log(`${test_name}: ${status}`); |
44 | 33 | } |
45 | 34 |
|
46 | | -test("journeyPlanner function works - case 1", |
47 | | - arraysEqual( |
48 | | - journeyPlanner(londonLocations, "river boat"), |
49 | | - ["London Bridge", "Greenwich"] |
50 | | - ) |
51 | | -) |
52 | | - |
53 | | -test("journeyPlanner function works - case 2", |
54 | | - arraysEqual( |
55 | | - journeyPlanner(londonLocations, "bus"), |
56 | | - ["Angel", "Tower Bridge", "Greenwich"] |
57 | | - ) |
58 | | -) |
59 | | - |
60 | | -test("journeyPlanner function works - case 3", |
61 | | - arraysEqual( |
62 | | - journeyPlanner(londonLocations, "tube"), |
63 | | - ["Angel", "London Bridge", "Tower Bridge"] |
64 | | - ) |
65 | | -) |
| 35 | +test( |
| 36 | + "journeyPlanner function works - case 1", |
| 37 | + journeyPlanner(londonLocations, "river boat"), |
| 38 | + ["Greenwich", "London Bridge"] |
| 39 | +); |
| 40 | + |
| 41 | +test( |
| 42 | + "journeyPlanner function works - case 2", |
| 43 | + journeyPlanner(londonLocations, "bus"), |
| 44 | + ["Angel", "Greenwich", "Tower Bridge"] |
| 45 | +); |
| 46 | + |
| 47 | +test( |
| 48 | + "journeyPlanner function works - case 3", |
| 49 | + journeyPlanner(londonLocations, "tube"), |
| 50 | + ["Angel", "Greenwich", "London Bridge", "Tower Bridge"] |
| 51 | +); |
0 commit comments