Untitled
unknown
javascript
a year ago
601 B
7
Indexable
const finalList = products .filter(el => (el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1) && (!inStockOnly || (inStockOnly && el.stocked)) ) .reduce((a, c) => { const isDifferentCategory = c.category !== a.lastCategory; a.output = [ ...a.output, isDifferentCategory ? <ProductCategoryRow key={c.category} category={c.category} /> : null, <ProductRow key={c.name} product={c} /> ].filter(Boolean); a.lastCategory = isDifferentCategory ? c.category : a.lastCategory; return a; }, { lastCategory: null, output: [] });
Editor is loading...
Leave a Comment