Untitled

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