Untitled
user_2672984
plain_text
2 years ago
755 B
4
Indexable
const filteredProducts = products.filter(product => {
let productName = product.name.toLowerCase().indexOf(filterText.toLowerCase());
return productName !== -1 && ((inStockOnly && product.stocked) || !inStockOnly);
});
const categorizedProducts = filteredProducts.reduce((accumulator, currentProduct) => {
currentProduct.category !== accumulator.lastCategory ?
accumulator.output.push(
<ProductCategoryRow key={currentProduct.category} category={currentProduct.category} />
) : null;
accumulator.lastCategory = currentProduct.category;
accumulator.output.push(<ProductRow key={currentProduct.name} product={currentProduct} />);
return accumulator;
}, { lastCategory: null, output: [] });
Editor is loading...
Leave a Comment