Untitled

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