Untitled

 avatar
user_4930908
javascript
2 months ago
581 B
12
Indexable
Never
const finalList = products
  .filter(el => 
    (el.name.toLowerCase().includes(filterText.toLowerCase())) &&
    (!inStockOnly || (inStockOnly && el.stocked))
  )
  .reduce((output, product) => {
    const categoryRow = product.category !== output.lastCategory
      ? [<ProductCategoryRow key={product.category} category={product.category} />]
      : [];
      
    return {
      lastCategory: product.category,
      output: [...output.output, ...categoryRow, <ProductRow key={product.name} product={product}/>]
    };
  }, { lastCategory: null, output: [] });
Leave a Comment