Untitled

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