Untitled

mail@pastecode.io avatar
unknown
javascript
2 months ago
497 B
13
Indexable
Never
const finalList = products.reduce((a, c) => {
  if (!c.name.toLowerCase().includes(filterText.toLowerCase()) || (inStockOnly && !c.stocked)) return a;

  const productRow = <ProductRow key={c.name} product={c} />;
  const categoryRow = c.category !== a.lastCategory && <ProductCategoryRow key={c.category} category={c.category} />;

  return {
    lastCategory: c.category,
    output: [...a.output, categoryRow, productRow].filter(Boolean)
  };
}, { lastCategory: null, output: [] });
Leave a Comment