Untitled

 avatar
unknown
javascript
a year ago
526 B
17
Indexable
const myFilter = products.filter(el =>
  el.name.toLowerCase().includes(filterText.toLowerCase()) && (inStockOnly ? el.stocked : true)
);
const finalList = myFilter.reduce((a, c) => {
  const { lastCategory, output } = a;
  const categoryRow = c.category !== lastCategory ? [...output, <ProductCategoryRow key={c.category} category={c.category} />] : output;
  return {
    lastCategory: c.category,
    output: [...categoryRow, <ProductRow key={c.name} product={c} />]
  };
}, { lastCategory: null, output: [] });
Editor is loading...
Leave a Comment