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-3.js
More file actions
93 lines (76 loc) · 3.1 KB
/
exercise-3.js
File metadata and controls
93 lines (76 loc) · 3.1 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Below are some restaurants in Glasgow. Each restaurant has a name, the number of total seats,
the number of customers in the restaurant at the moment and the menu with prices.
We want to build an object to simulate a Restaurant Finder application (see below restaurantFinderApplication).
1) Define a method findAvailableRestaurants which takes a number of people in parameter and returns
all the restaurant names which have the required number of seats available at the moment.
2) Define a method findRestaurantServingDish which takes a dish name in parameter and returns
all the restaurant names serving this dish.
3) Define a method countNumberOfRestaurantsInArea which takes an area of Glasgow in parameter (center, west),
and returns the number of restaurants in this area.
*/
let restaurant1 = {
name: "Paesano",
totalSeats: 10,
numberOfCustomers: 8,
address: {
city: "Glasgow",
area: "center"
},
menu: ["pizza", "calzone", "salad"]
};
let restaurant2 = {
name: "Ubiquitous Chip",
totalSeats: 20,
numberOfCustomers: 10,
address: {
city: "Glasgow",
area: "west"
},
menu: ["salad", "chocolate cake", "roast lamb"]
};
let restaurant3 = {
name: "Monkeyz",
totalSeats: 15,
numberOfCustomers: 8,
address: {
city: "Glasgow",
area: "center"
},
menu: ["stew", "chocolate cake", "panini"]
};
let restaurants = [restaurant1, restaurant2, restaurant3];
/*
DO NOT EDIT ANYTHING ABOVE THIS LINE
WRITE YOUR CODE BELOW
*/
let restaurantFinderApplication = {
applicationName: "Restaurant Finder",
applicationVersion: "1.0",
restaurants: restaurants,
findAvailableRestaurants: function (numberOfPeople) {
// Complete here
let availableRestaurants = restaurants.filter(res=> numberOfPeople <= res.totalSeats - res.numberOfCustomers).map(res=> res.name);
return availableRestaurants;
},
findRestaurantServingDish: function (dishName) {
// Complete here
let customRestaurant = restaurants.filter(res => res.menu.includes(dishName)).map(res => res.name);
return customRestaurant;
},
countNumberOfRestaurantsInArea: function (area) {
// Complete here
let count = 0;
let countRestaurant = restaurants.filter(res => res.address.area.includes(area)).map(res => count++ )
return count;
}
};
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
let restaurantsAvailableFor5People = restaurantFinderApplication.findAvailableRestaurants(5);
console.log(`Find available restaurants for 5 people: Expected result: Ubiquitous Chip,Monkeyz, actual result: ${restaurantsAvailableFor5People}`);
let restaurantsServingSalad = restaurantFinderApplication.findRestaurantServingDish("salad");
console.log(`Find restaurants serving salad: Expected result: Paesano,Ubiquitous Chip, actual result: ${restaurantsServingSalad}`);
let numberOfRestaurantsInCityCentre = restaurantFinderApplication.countNumberOfRestaurantsInArea("center");
console.log(`Number of restaurants in city centre: Expected result: 2, actual result: ${numberOfRestaurantsInCityCentre}`);