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
|
const express = require('express');
const app = express();
const port = 3000;
const tasks = [
{
id: 1,
description: 'Complete monthly financial report'
},
{
id: 2,
description: 'Plan team building activity'
},
{
id: 3,
description: 'Update project documentation'
}
];
app.get('/search', (req, res) => {
const query = req.query.query?.toLowerCase() || '';
const filteredTasks = tasks.filter(task => task.description.toLowerCase().includes(query));
const sortedTasks = filteredTasks.sort((a, b) => a.description.localeCompare(b.description));
res.json(sortedTasks);
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
|