-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBD2.2-HW-1.js
58 lines (47 loc) · 1.45 KB
/
BD2.2-HW-1.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
const express = require('express');
const app = express();
const port = 3000;
let temperatures = [22,26,19,30,23,28,17,31];
let prices = [80, 120, 95, 150, 60, 110];
let ratings = [4.2, 3.8, 2.5, 4.7, 3.0, 4.9, 3.6];
let names = ['Akshay', 'Priyanka', 'Arjun', 'Anushka', 'Rajesh', 'Kavita'];
function filterHighTemperatures(temp) {
return temp > 25;
}
app.get('/high-temperatures', (req, res) => {
const highTemperatures = temperatures.filter(filterHighTemperatures);
res.json(highTemperatures);
});
function filterLowPrices(price) {
return price <= 100;
}
app.get('/low-prices', (req, res) => {
const lowPrices = prices.filter(filterLowPrices);
res.json(lowPrices);
});
function filterHighRatings(rating) {
return rating > 3.5;
}
app.get('/high-ratings', (req, res) => {
const highRatings = ratings.filter(filterHighRatings);
res.json(highRatings);
});
function filterLongIndianNames(name) {
return name.length > 6;
}
app.get('/long-indian-names', (req, res) => {
const longNames = names.filter(filterLongIndianNames);
res.json(longNames);
});
function filterFindCheaperProduct(price, filterParam)
{
return price < filterParam;
}
app.get('/cheaper-products', (req, res) => {
const filterParam = parseInt(req.query.filterParam);
const cheaperProducts = prices.filter(prices => filterFindCheaperProduct(prices, filterParam));
res.json(cheaperProducts);
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});