Untitled
unknown
javascript
2 years ago
601 B
10
Indexable
const finalList = products
.filter(el =>
(el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1) &&
(!inStockOnly || (inStockOnly && el.stocked))
)
.reduce((a, c) => {
const isDifferentCategory = c.category !== a.lastCategory;
a.output = [
...a.output,
isDifferentCategory ? <ProductCategoryRow key={c.category} category={c.category} /> : null,
<ProductRow key={c.name} product={c} />
].filter(Boolean);
a.lastCategory = isDifferentCategory ? c.category : a.lastCategory;
return a;
}, { lastCategory: null, output: [] });
Editor is loading...
Leave a Comment