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