-
Notifications
You must be signed in to change notification settings - Fork 0
filter duplicate array #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
server.js
Outdated
|
|
||
| app.get('/', (req, res) => { | ||
| res.send('<center>Hello world</center> '); | ||
| const car = filter(cars); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно не фильтровать значения а на этапе добавления не давать добавлять дубли
server.js
Outdated
| name, | ||
| } = req.params; | ||
| res.send(`<center>Hello ${name}</center> `); | ||
| cars.push(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот тут проверить если значение уже есть в массиве то выдать сообщение об ошибке, иначе добавить в массив
|
|
||
| // больше не хуйни | ||
| app.get('/hello/:name', (req, res) => { | ||
| app.get('/cars/add/:name', (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Коротко и лаконично:
app.get('/cars/add/:name', (req, res) => {
const {
name,
} = req.params;
if (cars.indexOf(name) >= 0) {
res.send('Already exists');
} else {
cars.push(name);
res.send(${name} added);
}
});
filter duplicate array