Untitled

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