Untitled
user_8640854
javascript
2 years ago
659 B
15
Indexable
const myFilter = products.filter(el => (el.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1) && ((inStockOnly && el.stocked) || (!inStockOnly)) ); // console.log(myFilter) const finalList = myFilter.reduce(({ lastCategory, output }, curr) => { const isNewCategory = curr.category !== lastCategory; return { output: [ ...output, ...(isNewCategory ? [<ProductCategoryRow key={curr.category} category={curr.category} />] : []), <ProductRow key={curr.name} product={curr} /> ], lastCategory: curr.category }; }, { lastCategory: null, output: [] });
Editor is loading...
Leave a Comment