Homework12!

Homework12!
mail@pastecode.io avatar
unknown
javascript
2 months ago
546 B
2
Indexable
Never
  const myFilter = products.filter( el => {
    let set = (el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1);
    let output = set&&(inStockOnly && el.stocked) || set&&(!inStockOnly)
    return output})
  const finalList = myFilter.reduce( (a,c) => {
    (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: []})
Leave a Comment