-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (54 loc) · 1.59 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const PORT = 5000;
app.use(bodyParser.json());
let dataStore = [];
function processData(request) {
const { data } = request;
console.log(data);
const numbers = [];
const alphabets = [];
data.forEach(item => {
if (!isNaN(item)) {
numbers.push(item);
} else if (/[a-zA-Z]/.test(item)) {
alphabets.push(item);
}
});
const lowercaseAlphabets = alphabets.filter(char => /[a-z]/.test(char));
let highestLowercaseAlphabet = lowercaseAlphabets.length > 0 ? [lowercaseAlphabets.sort().pop()] : [];
const response = {
numbers: numbers,
alphabets: alphabets,
highest_lowercase_alphabet: highestLowercaseAlphabet
};
return response;
}
app.get('/bfhl', (req, res) => {
res.json({ operation_code: 1 });
});
app.post('/bfhl', (req, res) => {
const newData = req.body;
if (!newData || !newData.data) {
return res.status(400).json({ error: 'Data is required' });
}
const commonObj = {
is_success: true,
user_id: "suryansh_shankar_22072003",
email: "[email protected]",
roll_number: "21BEC0099",
}
const formatObj = processData(newData);
console.log(formatObj);
const respObj = {
...commonObj,
...formatObj,
}
dataStore.push(newData);
res.status(201).json(respObj);
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});