Untitled
Anonymous
JavaScript
01/02/2024 6:04 PM
581 B
18
Indexable
Never
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