Untitled

 avatar
user_3892690
javascript
2 years ago
533 B
4
Indexable
const finalList = products.reduce((result, product) => {
    const name = product.name.toLowerCase().includes(filterText.toLowerCase());
    const stockCondition = inStockOnly ? product.stocked : true;

    if (name && stockCondition) {
        if (product.category !== result[result.length - 1]?.key) {
            result.push(<ProductCategoryRow key={product.category} category={product.category} />);
        }
        result.push(<ProductRow key={product.name} product={product} />);
    }
    return result;
}, []);
Editor is loading...
Leave a Comment