-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (72 loc) · 1.9 KB
/
index.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
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
// Restaurant Manager
class restaurantManager {
//Array of Object
restaurantList = [{
//Restaurant Objects -> name, address, city
id: 1,
restaurantName: 'Punjabi Tadka',
address: 'Civil Lines',
city: 'Delhi'
},
{
id: 2,
restaurantName: 'Dominos',
address: 'Shubash Nagar',
city: 'Haldwani'
},
{
id: 3,
restaurantName: 'Burger King',
address: 'Kamla Nagar',
city: 'Delhi'
},
{
id: 4,
restaurantName: 'Chingari',
address: 'Bund Garden Road',
city: 'Pune'
},
{
id: 5,
restaurantName: 'KFC',
address: 'Anand Vihar',
city: 'Delhi'
}];
//Fn for printing Restaurant Names
printAllRestaurantNames = () => {
return this.restaurantList.map(restaurant => restaurant.restaurantName);
}
//Fn for filtering Restaurant Names by city
filterRestaurantsByCity = (cityname) => {
return this.restaurantList.filter(restaurant => restaurant.city == cityname);
}
}
const restaurantObject = new restaurantManager();
const output1 = restaurantObject.printAllRestaurantNames();
console.log(output1);
console.log(restaurantObject.filterRestaurantsByCity("Delhi"));
orderData = {
'Below 500': 20,
'500-1000': 29,
'1000-1500': 30,
'1500-2000': 44,
'Above 2000': 76
};
//Total no. of orders
const total = Object.values(orderData).reduce((prev, next) => prev + next);
console.log(total);
//Order proportion
const headers = Object.keys(orderData);
console.log(headers);
// % of order proportion
let arr = [];
const response = headers.map((item, index) => {
const obj = {
'id': index + 1,
'order': item,
'orderpercentage': ((orderData[item] / total) * 100).toFixed(2),
'restaurant': 'Punjabi Tadka'
}
arr.push(obj);
})
console.log(arr);