-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy path1418.js
36 lines (33 loc) · 867 Bytes
/
1418.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
var displayTable = function(orders) {
let res = [], foods = [], hm = {};
for (let order of orders) {
let food = order[2];
if (hm[food] == undefined) {
foods.push(food);
hm[food] = 0;
}
}
foods.sort();
hm = {};
for (let i = 0; i < foods.length; i++) {
hm[foods[i]] = i;
}
let a = Array(501);
for (let order of orders) {
let table = Number(order[1]);
a[table] = a[table] || Array(foods.length).fill(0);
a[table][hm[order[2]]]++;
}
foods.unshift("Table");
res.push(foods);
for (let i = 0; i < 501; i++) {
if (a[i]) {
let row = [String(i)];
for (let j = 0; j < foods.length - 1; j++) {
row.push(String(a[i][j]));
}
res.push(row);
}
}
return res;
};