Untitled

 avatar
user_8712311
javascript
a year ago
485 B
27
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