How to define two way for run code in filter method

Return the result of both conditions.

const filterCoins = currentCoins.filter(({ name, symbol }) =>
  name.toLowerCase().includes(search.toLowerCase()) ||
  symbol.toLowerCase().includes(search.toLowerCase())
);

Or a bit more succinct and DRY, place both values into an array as check that at least one of them meets the conditional test.

const filterCoins = currentCoins.filter(({ name, symbol }) => 
  [name, symbol].some(el => el.toLowerCase().includes(search.toLowerCase()))
);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top