Skip to content

Conversation

@alivls
Copy link
Owner

@alivls alivls commented Jan 16, 2019

filter duplicate array

server.js Outdated

app.get('/', (req, res) => {
res.send('<center>Hello world</center> ');
const car = filter(cars);
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут проверить если значение уже есть в массиве то выдать сообщение об ошибке, иначе добавить в массив

made changes

// больше не хуйни
app.get('/hello/:name', (req, res) => {
app.get('/cars/add/:name', (req, res) => {
Copy link
Collaborator

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);
}

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants