This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathexercise-2.js
More file actions
56 lines (41 loc) · 1.89 KB
/
exercise-2.js
File metadata and controls
56 lines (41 loc) · 1.89 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
53
54
55
56
/*
An array of travel destinations is defined below.
Each destination has a name, a distance from Glasgow, and a list of transportations available to go there.
1) Filter the travelDestinations array to return all destination names reachable within 500 kms.
2) Find a destination name reachable by ferry.
3) Find all the destination names that are both more than 300 kms far away and reachable by train.
*/
let destination1 = {
destinationName: "Edinburgh",
distanceKms: 80,
transportations: ["car", "bus", "train"]
};
let destination2 = {
destinationName: "London",
distanceKms: 650,
transportations: ["car", "bus", "train"]
};
let destination3 = {
destinationName: "Paris",
distanceKms: 900,
transportations: ["train", "plane"]
};
let destination4 = {
destinationName: "Dublin",
distanceKms: 350,
transportations: ["plane", "ferry"]
};
let travelDestinations = [destination1, destination2, destination3, destination4];
/*
DO NOT EDIT ANYTHING ABOVE THIS LINE
WRITE YOUR CODE BELOW
*/
let destinationNamesWithin500Kms = travelDestinations.filter(a => a.distanceKms < 500).map(b => b.destinationName);// Complete here
let destinationNameReachableByFerry = travelDestinations.find(c => c.transportations.includes(`ferry`)).destinationName;// Complete here
let destinationNamesMoreThan300KmsAwayByTrain = travelDestinations.filter(a => a.distanceKms > 300).filter(c => c.transportations.includes(`train`)).map(a => a.destinationName);// Complete here (PRINT THE RESULT IN THE CONSOLE USING FOREACH)
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
console.log(`Question 1) Expected result: Edinburgh,Dublin, actual result: ${destinationNamesWithin500Kms}`);
console.log(`Question 2) Expected result: Dublin, actual result: ${destinationNameReachableByFerry}`);
console.log(`Question 3) Expected result: London,Paris, actual result: ${destinationNamesMoreThan300KmsAwayByTrain}`);