Untitled

 avatar
user_0284075
javascript
a month ago
577 B
5
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