show me the better way to write this code?
filterdItems = []
const {
priceasc,
pricedesc
} = sortOptions;
if (priceasc)
filterdItems = _.orderBy(filterdItems, "price", "asc");
if (pricedesc)
filterdItems = _.orderBy(filterdItems, "price", "desc");
why have an object that has priceasc/pricedesc? you could directly pass the sort mode as string 'asc' or 'desc'
If you need these properties, then my suggestion is: _.orderBy(filteredItems, 'price', priceasc ? 'asc' : 'desc')
Обсуждают сегодня