Untitled

 avatar
user_8712311
javascript
2 months ago
485 B
24
Indexable
Never
const finalList = products
  .filter(el =>
    (el.name.toLowerCase().includes(filterText.toLowerCase()) &&
      (!inStockOnly || (inStockOnly && el.stocked)))
  )
  .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