Untitled
unknown
javascript
2 years ago
514 B
10
Indexable
const finalList = products
.filter(el =>
(el.name.toLowerCase().includes(filterText.toLowerCase()) &&
(!inStockOnly || (inStockOnly && el.stocked)))
)
.reduce((acc, curr) => {
if (curr.category !== acc.lastCategory) {
acc.output.push(<ProductCategoryRow key={curr.category} category={curr.category} />);
acc.lastCategory = curr.category;
}
acc.output.push(<ProductRow key={curr.name} product={curr} />);
return acc;
}, { lastCategory: null, output: [] });
Editor is loading...
Leave a Comment