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