-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestd.js
128 lines (109 loc) · 2.36 KB
/
testd.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const data = require('./data');
const fs = require("fs")
data.map((el)=> {
// el.categories = [];
el.categories = el.categories.map((la)=> la.trim());
});
// console.log(data);
let shortcategory = data.filter((a)=>{
if(a.categories.includes("North Indian")){
return a;
}
});
let rate = data.filter((a)=>{
if(a.rating > 4.1){
return a;
}
});
let filterobj = {
cat: ['North Indian', 'Chinese'], // [x]
rate: 3.5, // [x]
order: 'desc', // [x]
greater: 558, // [x]
top: 20// []
}
let alldone = Promise.all(
data.filter((a)=> {
if(filterobj.cat.length > 0){
if(a.categories.includes('North Indian')){
return a;
}
}
}))
// .then((res)=>{
// console.log(res);
// })
.then((res)=>{
if(filterobj.rate != undefined){
console.log("first")
alldone = res.filter((a)=>{
if(((a.rating != '-')?parseFloat(a.rating): 0) >= filterobj.rate){
return a;
}
})
return alldone;
}
})
// .then((res)=>{
// console.log(res);
// })
.then((res)=>{
if(filterobj.greater != undefined){
alldone = res.filter((a)=>{
if(a.numberOfOrders >= filterobj.greater){
return a;
}
})
}
return alldone;
})
// .then((res)=>{
// console.log(res);
// })
.then((res)=>{
res.sort((a,b)=>{
if(filterobj.order === 'desc'){
if(b.numberOfOrders > a.numberOfOrders){
return 1;
}
return -1;
}
})
return res;
})
.then((res)=>{
if(filterobj.top != undefined){
alldone = res.splice(0,filterobj.top);
}
fs.writeFileSync("./test.json", JSON.stringify(alldone));
return alldone;
})
// .then((res)=>{
// alldone = res;
// console.log(alldone);
// });
let numberorder = data.filter((a)=>{
if(a.numberOfOrders >= 558){
return a;
}
})
// for(let i = 0; i<data.length(); i++){
// }
let average = 0;
let sum = 0;
let temp = -1;
data.map((el)=>{
sum += el.numberOfOrders;
average = sum/data.length;
});
data.map((el)=>{
if( temp < el.numberOfOrders ){
temp = el.numberOfOrders;
}
})
console.log(temp);
console.log(sum);
console.log(average);
console.log(numberorder.length);
fs.writeFileSync("./test.json", JSON.stringify(alldone));
// console.log(short);