Untitled

mail@pastecode.io avatar
unknown
javascript
2 months ago
441 B
1
Indexable
Never
const myFilter = products.filter( el => (el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1) && (!inStockOnly || el.stocked))

const finalList = myFilter.reduce( (a,c) => {
    c.category !== a.lastCategory && a.output.push( <ProductCategoryRow key={c.category} category={c.category} />), a.lastCategory = c.category
    a.output.push(<ProductRow key={c.name} product={c} />)
    return a
},{lastCategory:null, output: []})
Leave a Comment