Skip to content

Proposal. Simplify point 4.5 (Filter) #1448

@hadson19

Description

@hadson19

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions