Skip to content

filter duplicate array - #2

Open
alivls wants to merge 2 commits into
masterfrom
feature/create-route-hello
Open

filter duplicate array#2
alivls wants to merge 2 commits into
masterfrom
feature/create-route-hello

Conversation

@alivls

@alivls alivls commented Jan 16, 2019

Copy link
Copy Markdown
Owner

filter duplicate array

Comment thread server.js Outdated

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Нужно не фильтровать значения а на этапе добавления не давать добавлять дубли

Comment thread server.js Outdated
name,
} = req.params;
res.send(`<center>Hello ${name}</center> `);
cars.push(name);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

made changes
Comment thread server.js

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

Copy link
Copy Markdown
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.

2 participants