Untitled
unknown
javascript
2 years ago
696 B
5
Indexable
//Homework 12+ const filteredProducts = products.filter((product) => { const nameMatches = product.name.toLowerCase().includes(filterText.toLowerCase()); const isInStock = inStockOnly ? product.stocked : true; return nameMatches && isInStock; }); const finalList = filteredProducts.reduce((result, current) => { if (current.category !== result.lastCategory) { result.output.push(<ProductCategoryRow key={current.category} category={current.category} />); result.lastCategory = current.category; } result.output.push(<ProductRow key={current.name} product={current} />); return result; }, { lastCategory: null, output: [] }); console.log(finalList);
Editor is loading...
Leave a Comment