Untitled

mail@pastecode.io avatar
unknown
javascript
2 months ago
533 B
6
Indexable
Never
const finalList = products
  .filter(el => 
    el.name.toLowerCase().includes(filterText.toLowerCase()) &&
    (!inStockOnly || (inStockOnly && el.stocked))
  )
  .reduce((acc, product) => {
    if (product.category !== acc.lastCategory) {
      acc.output.push(<ProductCategoryRow key={product.category} category={product.category} />);
      acc.lastCategory = product.category;
    }
    acc.output.push(<ProductRow key={product.name} product={product} />);
    return acc;
  }, { lastCategory: null, output: [] });
Leave a Comment