airbnb / airbnb/javascript

Proposal. Simplify point 4.5 (Filter)

Open
#1,448 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
148k
Forks
26.6k
PR merge metrics
No merged PRs in 30d

Description

In this part of best practice I found a part of code
```
// bad
inbox.filter((msg) => {
const { subject, author } = msg;
if (subject === 'Mockingbird') {
return author === 'Harper Lee';
} else {
return false;
}
});

// good
inbox.filter((msg) => {
const { subject, author } = msg;
if (subject === 'Mockingbird') {
return author === 'Harper Lee';
}

return false;
});
```

But, it seems that we can write this part of code better:

```
inbox.filter((msg) => {
const { subject, author } = msg;
return subject === 'Mockingbird' && author === 'Harper Lee';
});
```
Isn't it?

Thanks,
Andrii

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with point 4.5 (Filter) in the best-practice documentation and compare the existing “bad” and “good” examples with the proposed expression. Done means updating the example if the shorter filter is accepted and preserving the section’s intended guidance.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.