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