1
var displayTable = function (orders) {5
for (var i = 0; i < orders.length; i++) {6
//if entry of table doesn't exist in mapOrders7
if (mapOrders[orders[i][1]] == undefined) {8
//conver table number to integer9
var tableNo = Number(orders[i][1]);10
mapOrders[tableNo] = {};11
mapOrders[tableNo][orders[i][2]] = 1;12
//if table number doesn't exist in table array, push it in the table array13
if (!tables.includes(tableNo)) {16
//if dish doesn't exist in dishes array, push it in the dishes array17
if (!dishes.includes(orders[i][2])) {18
dishes.push(orders[i][2]);21
//if entry of table exists in mapOrders22
//conver table number to integer23
var tableNo = Number(orders[i][1]);24
var entry = mapOrders[tableNo];25
//check if entry of dish exists in for that table in mapOrders26
if (entry[orders[i][2]] == undefined) {27
entry[orders[i][2]] = 1;29
entry[orders[i][2]] = entry[orders[i][2]] + 1;31
//if dish doesn't exist in dishes array, push it in the dishes array32
if (!dishes.includes(orders[i][2])) {33
dishes.push(orders[i][2]);37
//sort tables and dishes38
tables.sort(function (a, b) {42
//append word "Table" with all dish names om row[0] of result43
var res = [["Table"]];44
for (var i = 0; i < dishes.length; i++) {45
res[0].push(dishes[i]);47
// read through map based on sorted table order48
for (var i = 0; i < tables.length; i++) {49
// append result in a temp array51
//converting number to string using ""+52
tmp.push("" + tables[i]);53
for (var j = 0; j < dishes.length; j++) {54
if (mapOrders[tables[i]][dishes[j]] == undefined) {55
//if dish doesn't exist against that table then append "0" to the result for that dish58
//if dish exists against that table then append value in mapOrders for that pair of (table,dish) to the result59
tmp.push("" + mapOrders[tables[i]][dishes[j]]);62
//append the temp array in result