Untitled

 avatar
unknown
plain_text
a year ago
648 B
6
Indexable
  const myFilter = products.filter( el => {
    let output = 
      (el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1) &&
      (inStockOnly && el.stocked) ||
      (el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1) &&
      (!inStockOnly)
    return output
  })

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