Untitled

 avatar
unknown
javascript
a year ago
556 B
16
Indexable
const filteredProducts = products.filter(
    (pd) =>
    pd.name.toLowerCase().includes(filterText.toLowerCase()) &&
      (inStockOnly ? pd.stocked : true)
  );
  const finalList = filteredProducts.reduce(
    (rs, pd) => {
      if (pd.category !== rs.lastCategory) {
        rs.output.push(<ProductCategoryRow key={pd.category} category={pd.category} />);
        rs.lastCategory = pd.category;
      }
      rs.output.push(<ProductRow key={pd.name} product={pd} />);
      return rs;
    },
    { lastCategory: null, output: [] }
  );
Leave a Comment