-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
54 lines (45 loc) · 1.32 KB
/
index.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
import _ from 'lodash'
import { createServer } from 'node:http'
const largeDataset = Array.from({ length: 1e4 }, (_, id) => ({
id,
name: `User ${id}`,
isActive: id % 2 === 0,
}));
function issueRoute() {
const clonedData = _.cloneDeep(largeDataset);
const activeUsers = _.filter(clonedData, { isActive: true });
const transformedUsers = _.map(activeUsers, (user) => ({
...user,
name: user.name.toUpperCase(),
}));
return transformedUsers;
}
function noIssueRoute() {
const transformedUsers = largeDataset
.filter((user) => user.isActive)
.map((user) => ({
...user,
name: user.name.toUpperCase(),
}));
return transformedUsers;
}
createServer(
function routes(req, res) {
if (req.url === '/issue') {
const transformedUsers = issueRoute();
res.end(JSON.stringify(transformedUsers));
return
}
if (req.url === '/no-issue') {
const transformedUsers = noIssueRoute();
res.end(JSON.stringify(transformedUsers));
return
}
res.writeHead(404);
res.end('Not Found');
return
})
.listen(3000)
.once('listening', function onListening() {
console.log('Server started on http://localhost:3000');
});