Untitled

user_8158302 avatar
user_8158302
javascript
01/03/2024 3:47 PM
648 B
22
Indexable
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: [] });
Editor is loading...
Leave a Comment