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